diff --git a/factoriel.php b/factoriel.php deleted file mode 100755 index fa51a1215f40fbb52898fe3ff2efa4a76693de52..0000000000000000000000000000000000000000 --- a/factoriel.php +++ /dev/null @@ -1,25 +0,0 @@ -<html> - <head> - <title>M2GPI</title> - </head> - <body> - <form method="POST" action="factoriel.php"> - <input type="submit" name="calcul" value="Calculer"/> - le factoriel de : <input type="number" name="input_value"/> - </form> - <?php - if (isset($_POST['calcul'])) { - - $input_value = $_POST['input_value']; - $factoriel = 1; - - for ($i=$_POST['input_value']; $i > 0 ; $i--) { - echo $factoriel . " * " . $i . "<br>"; - $factoriel = $factoriel * $i; - } - - echo "Le factoriel de " . $_POST['input_value'] . " est " . $factoriel; - } - ?> - </body> -</html> diff --git a/factoriel_tableau.php b/factoriel_tableau.php deleted file mode 100755 index 4a718fc9957d2113f9e09507979fbe605e9123cc..0000000000000000000000000000000000000000 --- a/factoriel_tableau.php +++ /dev/null @@ -1,32 +0,0 @@ -<html> - <head> - <title>M2GPI</title> - </head> - <body> - <table> - <thead> - <tr> - <th>Factoriel</th> - <th>Résultat</th> - <th>Type</th> - </tr> - </thead> - <tbody> - <?php - for ($i=0; $i < 100; $i++) { - $f = 1; - for ($n=$i; $n > 0; $n--) { - $f = $f * $n; - } - echo " - <tr> - <td>" . $i . "</td> - <td>" . $f . "</td> - <td>" . gettype($f) . "</td> - </tr>"; - } - ?> - </tbody> - </table> - </body> -</html> diff --git a/fibonacci.php b/fibonacci.php deleted file mode 100755 index f3ca578086d646bf03f14c396c76a474a2357363..0000000000000000000000000000000000000000 --- a/fibonacci.php +++ /dev/null @@ -1,62 +0,0 @@ -<html> - <head> - <title>M2GPI</title> - </head> - <body> - <form method="POST" action="fibonacci.php"> - <input type="submit" name="calcul" value="Calculer"/> - le fibonacci de <input type="number" name="input"/> ? - </form> - <?php - function iterativeFibonacci($count) { - $fibonacci = array(0,1); - for ($index=2; $index <= $count; $index++) { - $fibonacci[$index] = $fibonacci[$index-1] + $fibonacci[$index-2]; - } - return $fibonacci[$count]; - } - - function recursiveFibonacci($count) { - if ($count == 0) { - return 0; - } elseif ($count == 1) { - return 1; - } else { - return (recursiveFibonacci($count - 1) + recursiveFibonacci($count - 2)); - } - } - if (isset($_POST['calcul']) && $_POST['input']) { - - echo "<h3>Fonction itérative</h3>"; - $start_time = microtime(true); - echo "<p>L'occurence n°" . $_POST['input'] . " de la suite de fibonacci est " . iterativeFibonacci($_POST['input']) . "</p>"; - echo "<p>Le temps d'exécution est de " . number_format((microtime(true) - $start_time), 6) . " seconde(s)"; - - echo "<h3>Fonction récursive</h3>"; - $start_time = microtime(true); - echo "<p>L'occurence n°" . $_POST['input'] . " de la suite de fibonacci est " . recursiveFibonacci($_POST['input']) . "</p>"; - echo "<p>Le temps d'exécution est de " . number_format((microtime(true) - $start_time), 6) . " seconde(s)"; - - } else { - echo "<p>Veuillez fournir un nombre à évaluer.</p>"; - } - ?> - <table> - <tr> - <th>Fibonacci</th> - <th>Itératif</th> - <th>Récursif</th> - </tr> - <?php - for ($i=0; $i < 35; $i++) { - $start_time = microtime(true); - echo "<tr><td>" . iterativeFibonacci($i) . "</td>"; - echo "<td>" . number_format((microtime(true) - $start_time), 6) . "s</td>"; - $start_time = microtime(true); - recursiveFibonacci($i); - echo "<td>" . number_format((microtime(true) - $start_time), 6) . "s</td></tr>"; - } - ?> - </table> - </body> -</html> diff --git a/oop_rand_array_to_file.php b/oop_rand_array_to_file.php deleted file mode 100755 index 6f2aac54d8949094bf5efeeec116693fea5b8aaf..0000000000000000000000000000000000000000 --- a/oop_rand_array_to_file.php +++ /dev/null @@ -1,227 +0,0 @@ -<?php - class RandArrayClass - { - private $array = array(); - private $sorted = false; - private $filepath; - - # A l'instanciation de l'objet, initialise un tableau de valeurs aléatoires - function __construct ($size = 20, $min = 1, $max = 1000, $path = './oop_rand_array_to_file.txt') { - $this->filepath = $path; - for ($i=0; $i < $size; $i++) { - $this->array[] = rand($min, $max); - } - } - - # A la destruction de l'objet, sauvegarde les valeurs du tableau dans un fichier - function __destruct () { - if ($file = fopen($this->filepath, 'a')) { - try { - fputs($file, date("H:i:s") . PHP_EOL); - for ($i=0; $i < count($this->array); $i++) { - fputs($file, $this->array[$i] . chr(10)); - } - } catch (Exception $e) { - echo 'Caught exception: ', $e->getMessage(), "\n"; - } finally { - fclose($file); - } - } - } - - # Retourne le tableau - public function getArray() { - return $this->array; - } - - # Définit le tableau - public function setArray($array) { - $this->array = $array; - } - - # Calcule la moyenne des valeurs du tableau - public function calculateAverageValue() : int { - $int = (int)0; - $count = count($this->array); - for ($i=0; $i < $count; $i++) { - $int = $int + $this->array[$i]; - } - $int = $int / count($this->array); - return $int; - } - - # Trouve la valeur minimale du tableau - public function findMinimalValue() : int { - $int = $this->array[0]; - $count = count($this->array); - for ($i=0; $i < $count; $i++) { - if ($this->array[$i] < $int) { - $int = $this->array[$i]; - } - } - return $int; - } - - # Trouve la valeur maximale du tableau - public function findMaximalValue() : int { - $int = $this->array[0]; - $count = count($this->array); - for ($i=0; $i < $count; $i++) { - if ($this->array[$i] > $int) { - $int = $this->array[$i]; - } - } - return $int; - } - - # Trie le tableau en ordre ascendant - public function bubbleSort() { - $temp = (int)0; - $count = count($this->array); - $swapped = (bool)true; - while ($swapped) { - $swapped = false; - $count = $count - 1; - for ($i=0; $i < $count; $i++) { - if ($this->array[$i] > $this->array[$i + 1]) { - $swapped = true; - $temp = $this->array[$i + 1]; - $this->array[$i + 1] = $this->array[$i]; - $this->array[$i] = $temp; - } - } - } - $this->sorted = true; - } - - # Trouve l'index d'une valeur par recherche dichotomique - # Trie le tableau s'il ne l'est pas encore - public function searchValue($value) : int { - if (!$this->sorted) { - $this->bubbleSort(); - } - $min = (int)0; - $max = count($this->array) - 1; - while ($min <= $max) { - $index = floor(($min + $max) / 2); - if ($this->array[$index] == $value) { - return $index; - } elseif ($this->array[$index] < $value) { - $min = $index + 1; - } elseif ($this->array[$index] > $value) { - $max = $index - 1; - } - } - return -1; - } - } - - function displayGenerateForm() : string { - $string = - '<form method="POST" action="oop_rand_array_to_file.php"> - <input type="number" name="size" placeholder="number of entries"/><br> - <input type="number" name="min" placeholder="minimum values"/><br> - <input type="number" name="max" placeholder="maximal values"/><br> - <input type="submit" name="generate" value="Generate array"/> - </form>'; - return $string; - } - - function displaySearchForm($array) : string { - $string = - '<form method="POST" action="oop_rand_array_to_file.php"> - <input type="number" name="input" placeholder="value to find"/><br> - <input type="submit" name="search" value="Search in array"/>'; - foreach($array as $value) { - $string .= '<input type="hidden" name="array[]" value="' . htmlspecialchars($value) . '">'; - } - $string .= '</form>'; - return $string; - } - - function displayArray($array) : string { - $string = "<table><tr><th>Index</th><th>Value</th></tr>"; - $count = count($array); - for ($i=0; $i < $count; $i++) { - $string .= "<tr><td>" . $i . "</td>"; - $string .= "<td>" . $array[$i] . "</td></tr>"; - } - $string .= "</table>"; - return $string; - } -?> - -<html> - <!-- - trier les valeurs par tri à bulle et les écrire dans un fichier - en programmation orientée objet - --> - <head> - <title>M2GPI</title> - <style> - body { - display: flex; - flex-direction: column; - } - #forms { - margin: auto; - display: flex; - align-items: flex-end; - align-content: space-between; - } - #results { - margin: auto; - } - #tables { - margin: auto; - display: flex; - align-content: space-between; - } - #forms > form { - margin: 0 1em 0 1em; - } - #tables > div { - margin: 0 5em 0 5em;; - } - </style> - </head> - <body> - <?php - if (isset($_POST['search']) && $_POST['input'] && $_POST['array']) { - $array = new RandArrayClass(); - $array->setArray($_POST['array']); - $input = $_POST['input']; - } elseif (isset($_POST['generate']) && $_POST['size'] && $_POST['min'] && $_POST['max']) { - $array = new RandArrayClass($_POST['size'], $_POST['min'], $_POST['max']); - } else { - $array = new RandArrayClass(); - } - - echo '<h1>M2GPI2024 Algorithmie</h1>'; - echo '<div id="forms">'; - echo displayGenerateForm(); - echo displaySearchForm($array->getArray()); - echo '</div><div id="tables">'; - echo '<div><h3>Unordered</h3>'; - echo displayArray($array->getArray()); - echo '</div><div><h3>Ordered</h3>'; - $array->bubbleSort(); - echo displayArray($array->getArray()); - echo '</div><div id="results">'; - echo '<h3>Results</h3>'; - echo "<p>Average value is " . $array->calculateAverageValue() . "</p>"; - echo "<p>Smallest value is " . $array->findMinimalValue() . "</p>"; - echo "<p>Largest value is " . $array->findMaximalValue() . "</p>"; - if (isset($input)) { - $result = $array->searchValue($input); - if ($result > -1) { - echo "Value " . $input . " exists at index " . $result; - } else { - echo "Value " . $input . " doesn't exist"; - } - } - echo '</div></div>'; - unset($array); - ?> - </body> -</html> \ No newline at end of file diff --git a/prime.php b/prime.php deleted file mode 100755 index 15eeeeb27346dc1f54602a86d519e40fbcb0f774..0000000000000000000000000000000000000000 --- a/prime.php +++ /dev/null @@ -1,36 +0,0 @@ -<html> - <head> - <title>M2GPI</title> - </head> - <body> - <form method="POST" action="prime.php"> - <input type="submit" name="calcul" value="Calculer"/> - si <input type="number" name="input"/> est un nombre premier ? - </form> - <?php - - - function isPrime($n) { - for ($i=2; $i < $n ; $i++) { - if ($n % $i == 0) { - return false; - } - } - return true; - } - - - if (isset($_POST['calcul']) && $_POST['input']) { - if ($_POST['input'] > 2 && isPrime($_POST['input'])) { - echo $_POST['input'] . " est un nombre premier."; - } else { - echo $_POST['input'] . " n'est pas un nombre premier."; - } - } else { - echo "Veuillez fournir un nombre à évaluer."; - } - - - ?> - </body> -</html> diff --git a/prime_hundred.php b/prime_hundred.php deleted file mode 100755 index c930da1a97cd871168c7b270c7c878f5c5aa5b28..0000000000000000000000000000000000000000 --- a/prime_hundred.php +++ /dev/null @@ -1,28 +0,0 @@ -<html> - <head> - <title>M2GPI</title> - </head> - <body> - <?php - function isPrime($n) { - for ($i=2; $i < $n ; $i++) { - if ($n % $i == 0) { - return false; - } - } - return true; - } - - $primes = array(); - for ($i=2; count($primes) < 100; $i++) { - if (isPrime($i)) { - $primes[] = $i; - } - } - - foreach ($primes as $key => $value) { - echo $key . " : " . $value . "<br>"; - } - ?> - </body> -</html> diff --git a/rand_array.php b/rand_array.php deleted file mode 100755 index 846ec7408a387768421b8d25d4d9c0831beedcd7..0000000000000000000000000000000000000000 --- a/rand_array.php +++ /dev/null @@ -1,183 +0,0 @@ -<html> - <!-- - Calcul sur tableau - 1 - générer un tableau avec N nombres aléatoires - 2 - calculer la moyenne, le plus petit et le plus grand - 3 - trier les valeurs par tri à bulle et les afficher - 4 - rechercher une valeur dans la table par dichotomie - --> - <head> - <title>M2GPI</title> - <style> - body { - display: flex; - flex-direction: column; - } - #forms { - margin: auto; - display: flex; - align-items: flex-end; - align-content: space-between; - } - #results { - margin: auto; - } - #tables { - margin: auto; - display: flex; - align-content: space-between; - } - #forms > form { - margin: 0 1em 0 1em; - } - #tables > div { - margin: 0 5em 0 5em;; - } - </style> - </head> - <body> - <?php - function displayGenerateForm() : string { - $string = - '<form method="POST" action="rand_array.php"> - <input type="number" name="size" placeholder="number of entries"/><br> - <input type="number" name="min" placeholder="minimum values"/><br> - <input type="number" name="max" placeholder="maximal values"/><br> - <input type="submit" name="generate" value="Generate array"/> - </form>'; - return $string; - } - - function displaySearchForm($array) : string { - $string = - '<form method="POST" action="rand_array.php"> - <input type="number" name="input" placeholder="value to find"/><br> - <input type="submit" name="search" value="Search in array"/>'; - foreach($array as $value) { - $string .= '<input type="hidden" name="array[]" value="' . $value . '">'; - } - $string .= '</form>'; - return $string; - } - - function displayArray($array) : string { - $string = "<table><tr><th>Index</th><th>Value</th></tr>"; - $count = count($array); - for ($i=0; $i < $count; $i++) { - $string .= "<tr><td>" . $i . "</td>"; - $string .= "<td>" . $array[$i] . "</td></tr>"; - } - $string .= "</table>"; - return $string; - } - - function generateRandArray($size = 20, $min = 1, $max = 1000) : array { - $array = array(); - for ($i=0; $i < $size; $i++) { - $array[] = rand($min, $max); - } - return $array; - } - - function calculateAverage($array) : int { - $int = (int)0; - $count = count($array); - for ($i=0; $i < $count; $i++) { - $int = $int + $array[$i]; - } - $int = $int / count($array); - return $int; - } - - function calculateMinimum($array) : int { - $int = $array[0]; - $count = count($array); - for ($i=0; $i < $count; $i++) { - if ($array[$i] < $int) { - $int = $array[$i]; - } - } - return $int; - } - - function calculateMaximum($array) : int { - $int = $array[0]; - $count = count($array); - for ($i=0; $i < $count; $i++) { - if ($array[$i] > $int) { - $int = $array[$i]; - } - } - return $int; - } - - function bubbleSort($array) : array { - $temp = (int)0; - $count = count($array); - $swapped = (bool)true; - while ($swapped) { - $swapped = false; - $count = $count - 1; - for ($i=0; $i < $count; $i++) { - if ($array[$i] > $array[$i + 1]) { - $swapped = true; - $temp = $array[$i + 1]; - $array[$i + 1] = $array[$i]; - $array[$i] = $temp; - } - } - } - return $array; - } - - function searchValue($value, $array) : int { - $min = (int)0; - $max = count($array) - 1; - while ($min <= $max) { - $index = floor(($min + $max) / 2); - if ($array[$index] == $value) { - return $index; - } elseif ($array[$index] < $value) { - $min = $index + 1; - } elseif ($array[$index] > $value) { - $max = $index - 1; - } - } - return -1; - } - - if (isset($_POST['search']) && $_POST['input'] && $_POST['array']) { - $input = $_POST['input']; - $array = $_POST['array']; - } elseif (isset($_POST['generate']) && $_POST['size'] && $_POST['min'] && $_POST['max']) { - $array = generateRandArray($_POST['size'], $_POST['min'], $_POST['max']); - } else { - $array = generateRandArray(); - } - $sortedArray = bubbleSort($array); - echo '<h1>M2GPI2024 Algorithmie</h1>'; - echo '<div id="forms">'; - echo displayGenerateForm(); - echo displaySearchForm($array); - echo '</div><div id="results">'; - echo '<h3>Results</h3>'; - echo "<p>Average value is " . calculateAverage($array) . "</p>"; - echo "<p>Smallest value is " . calculateMinimum($array) . "</p>"; - echo "<p>Largest value is " . calculateMaximum($array) . "</p>"; - if (isset($input)) { - $result = searchValue($input, $sortedArray); - if ($result > -1) { - echo "Value " . $input . " exists at index " . $result; - } else { - echo "Value " . $input . " doesn't exist"; - } - } - echo '</div><div id="tables">'; - echo '<div><h3>Unordered</h3>'; - echo displayArray($array); - echo '</div><div><h3>Ordered</h3>'; - echo displayArray($sortedArray); - echo '</div></div>'; - ?> - </body> -</html> \ No newline at end of file diff --git a/rand_array_to_file.php b/rand_array_to_file.php deleted file mode 100755 index 70f9ab87e4b294881e011f00b88422545a0cfe75..0000000000000000000000000000000000000000 --- a/rand_array_to_file.php +++ /dev/null @@ -1,203 +0,0 @@ -<html> - <!-- - trier les valeurs par tri à bulle et les écrire dans un fichier - --> - <head> - <title>M2GPI</title> - <style> - body { - display: flex; - flex-direction: column; - } - #forms { - margin: auto; - display: flex; - align-items: flex-end; - align-content: space-between; - } - #results { - margin: auto; - } - #tables { - margin: auto; - display: flex; - align-content: space-between; - } - #forms > form { - margin: 0 1em 0 1em; - } - #tables > div { - margin: 0 5em 0 5em;; - } - </style> - </head> - <body> - <?php - function displayGenerateForm() : string { - $string = - '<form method="POST" action="rand_array.php"> - <input type="number" name="size" placeholder="number of entries"/><br> - <input type="number" name="min" placeholder="minimum values"/><br> - <input type="number" name="max" placeholder="maximal values"/><br> - <input type="submit" name="generate" value="Generate array"/> - </form>'; - return $string; - } - - function displaySearchForm($array) : string { - $string = - '<form method="POST" action="rand_array.php"> - <input type="number" name="input" placeholder="value to find"/><br> - <input type="submit" name="search" value="Search in array"/>'; - foreach($array as $value) { - $string .= '<input type="hidden" name="array[]" value="' . $value . '">'; - } - $string .= '</form>'; - return $string; - } - - function displayArray($array) : string { - $string = "<table><tr><th>Index</th><th>Value</th></tr>"; - $count = count($array); - for ($i=0; $i < $count; $i++) { - $string .= "<tr><td>" . $i . "</td>"; - $string .= "<td>" . $array[$i] . "</td></tr>"; - } - $string .= "</table>"; - return $string; - } - - function generateRandArray($size = 20, $min = 1, $max = 1000) : array { - $array = array(); - for ($i=0; $i < $size; $i++) { - $array[] = rand($min, $max); - } - return $array; - } - - function calculateAverage($array) : int { - $int = (int)0; - $count = count($array); - for ($i=0; $i < $count; $i++) { - $int = $int + $array[$i]; - } - $int = $int / count($array); - return $int; - } - - function calculateMinimum($array) : int { - $int = $array[0]; - $count = count($array); - for ($i=0; $i < $count; $i++) { - if ($array[$i] < $int) { - $int = $array[$i]; - } - } - return $int; - } - - function calculateMaximum($array) : int { - $int = $array[0]; - $count = count($array); - for ($i=0; $i < $count; $i++) { - if ($array[$i] > $int) { - $int = $array[$i]; - } - } - return $int; - } - - function bubbleSort($array) : array { - $temp = (int)0; - $count = count($array); - $swapped = (bool)true; - while ($swapped) { - $swapped = false; - $count = $count - 1; - for ($i=0; $i < $count; $i++) { - if ($array[$i] > $array[$i + 1]) { - $swapped = true; - $temp = $array[$i + 1]; - $array[$i + 1] = $array[$i]; - $array[$i] = $temp; - } - } - } - return $array; - } - - function searchValue($value, $array) : int { - $min = (int)0; - $max = count($array) - 1; - while ($min <= $max) { - $index = floor(($min + $max) / 2); - if ($array[$index] == $value) { - return $index; - } elseif ($array[$index] < $value) { - $min = $index + 1; - } elseif ($array[$index] > $value) { - $max = $index - 1; - } - } - return -1; - } - - function writeArrayValuesToFile($array, $path) : bool { - if ($file = fopen($path, 'a')) { - try { - fputs($file, chr(10) . date("H:i:s")); - for ($i=0; $i < count($array); $i++) { - fputs($file, $array[$i] . chr(10)); - } - } catch (Exception $e) { - echo 'Caught exception: ', $e->getMessage(), "\n"; - } finally { - fclose($file); - } - return true; - } - return false; - } - - if (isset($_POST['search']) && $_POST['input'] && $_POST['array']) { - $input = $_POST['input']; - $array = $_POST['array']; - } elseif (isset($_POST['generate']) && $_POST['size'] && $_POST['min'] && $_POST['max']) { - $array = generateRandArray($_POST['size'], $_POST['min'], $_POST['max']); - } else { - $array = generateRandArray(); - } - $sortedArray = bubbleSort($array); - $path = './rand_array_to_file.txt'; - - echo '<h1>M2GPI2024 Algorithmie</h1>'; - echo '<div id="forms">'; - echo displayGenerateForm(); - echo displaySearchForm($array); - echo '</div><div id="results">'; - echo '<h3>Results</h3>'; - echo "<p>Average value is " . calculateAverage($array) . "</p>"; - echo "<p>Smallest value is " . calculateMinimum($array) . "</p>"; - echo "<p>Largest value is " . calculateMaximum($array) . "</p>"; - if (writeArrayValuesToFile($sortedArray, $path)) { - echo "<p>Values saved to <br>'" . $path . "'</p>"; - } else { - echo "<p>Couldn't save values to <br>'" . $path . "'</p>"; - } - if (isset($input)) { - $result = searchValue($input, $sortedArray); - if ($result > -1) { - echo "Value " . $input . " exists at index " . $result; - } else { - echo "Value " . $input . " doesn't exist"; - } - } - echo '</div><div id="tables">'; - echo '<div><h3>Unordered</h3>'; - echo displayArray($array); - echo '</div><div><h3>Ordered</h3>'; - echo displayArray($sortedArray); - echo '</div></div>'; - ?> - </body> -</html> \ No newline at end of file diff --git a/rectangle.php b/rectangle.php deleted file mode 100755 index 75e57c392054de0e9fcb8b6aa3f6afabfbf729c2..0000000000000000000000000000000000000000 --- a/rectangle.php +++ /dev/null @@ -1,18 +0,0 @@ -<html> - <head> - <title>M2GPI</title> - </head> - <body> - <form method="POST" action="rectangle.php"> - Largeur : <input type="number" name="largeur"/> - Longueur : <input type="number" name="longueur"/> - <input type="submit" name="calcul" value="Calculer"/> - </form> - <?php - if (isset($_POST['calcul'])) { - $surface = $_POST['largeur'] * $_POST['longueur']; - echo "La surface du rectangle est " . $surface; - } - ?> - </body> -</html>