Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions IsPrime/is_prime.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@

/*
<!--
Is Prime?
Write a php function called is_prime that checks the number if it's prime or not!
If number is prime print: "The number (X) is prime", if not print: "number (X) is not prime".
*/
-->
<?php include '../includes/header.php' ?>

<form action="#" method="post">
<input type="text" name="$number" placeholder="type number">
<button>Is Prime</button>
</form>

<?php

function is_prime() {
$n = $_POST['$number'];

function is_prime($n){
// code goes here
$flag = false;
if ($n === "1") {
echo "Number $n is not Prime <br>";
}
elseif ($n > 1) {
for ($i = 2; $i <$n ; $i++) {
if ($n % $i === 0) {
$flag = true;
}
}
if (!$flag) {
echo "Number $n is Prime <br>";
}
elseif ($flag) {
echo "Number $n is not Prime <br>";
}
}
}

if(isset($_POST['$number'])) {
is_prime();
}

}
?>
<?php include '../includes/footer.php' ?>
59 changes: 51 additions & 8 deletions MilitaryTime/toMilitary.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,56 @@

/*
Is Prime?
Write a php function called is_prime that checks the number if it's prime or not!
If number is prime print: "The number (X) is prime", if not print: "number (X) is not prime".
*/
<!-- Given a string that represents time in hours and minutes, convert the string to military time (if necessary)..
-->

<?php include '../includes/header.php' ?>

function is_prime($n){
// code goes here
<form action="#" method="post">
<input type="text" name="$time" placeholder="type time">
<button>Get Military Time</button>
</form>

<?php

}
function toMilitary () {
$str = "";
$time = $_POST['$time'];


if (substr($time, -2) === "am") {
$time = str_split($time);
array_splice($time, -2);
$time = join('', $time);
if (strlen($time) === 4) {
$time = "0" . $time;
}
if (substr($time, 0, -3) === "12") {
$time = "00" . substr($time, -3);
}
}

elseif (substr($time, -2) ==="pm") {
$time = str_split($time);
array_splice($time, -2);
$time = join('', $time);

if (substr($time, 0, -3) !== "12") {
$str = substr($time, -3);
$time = str_split($time);
array_splice($time, -2);
$time = join('', $time);
$time = str_split($time);
array_splice($time, -1);
$time = join('', $time);
$time = strval((intval($time) + 12)) . $str;

}
}
echo $time;
}

if(isset($_POST['$time'])) {
toMilitary();
}

?>
<?php include '../includes/footer.php' ?>
59 changes: 39 additions & 20 deletions angrams/angrams.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
<?php
/**
* Given a single input string, write a function that outputs an array of strings with every possible
* combination of letters.
*
* At first, don't worry about repeated (duplicate) strings.
*
* What time complexity is your solution?
*
* Extra credit: De-duplicate your return array without using uniq().
*/
<!-- Given a single input string, write a function that outputs an array of strings with every possible
combination of letters.

At first, don't worry about repeated (duplicate) strings.

What time complexity is your solution?

Extra credit: De-duplicate your return array without using uniq().

example usage:
angrams('abc');
echo(anagrams); // [ 'abc', 'acb', 'bac', 'bca', 'cab', 'cba' ] -->

<?php include '../includes/header.php' ?>

<form action="#" method="post">
<input type="text" name="$string" placeholder="type word">
<button>Get Military Time</button>
</form>

<?php

function angrams(){

$string = $_POST['$string'];
$output = array();

for ($i = 0; $i < strlen($string); $i++) {
array_push($output, $string[$i]);
}
print_r ($output);
}

if(isset($_POST['$string'])) {
angrams();
}

?>
<?php include '../includes/footer.php' ?>

/**
* example usage:
* angrams('abc');
* echo(anagrams); // [ 'abc', 'acb', 'bac', 'bca', 'cab', 'cba' ]
*/


echo angrams("abc");



function angrams($string){

}

?>
2 changes: 2 additions & 0 deletions includes/footer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
</body>
</html>
6 changes: 6 additions & 0 deletions includes/header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<title>Toy-Problem</title>
</head>
<body>