From 5cfc94e04409651e56705c9bb497aeed834ff55b Mon Sep 17 00:00:00 2001
From: KAPIAS NICOLAS <nicolas.kapias@etu.unistra.fr>
Date: Mon, 31 Mar 2025 14:09:19 +0200
Subject: [PATCH] chore: clean repo tree

---
 2024-12-18/rectangle.php              |  18 ++
 2025-01-13/factoriel.php              |  25 +++
 2025-01-13/factoriel_tableau.php      |  32 ++++
 2025-01-13/prime.php                  |  36 ++++
 2025-01-13/prime_hundred.php          |  28 ++++
 2025-02-04/fibonacci.php              |  62 +++++++
 2025-02-04/rand_array.php             | 183 +++++++++++++++++++++
 2025-03-14/oop_rand_array_to_file.php | 227 ++++++++++++++++++++++++++
 2025-03-14/rand_array_to_file.php     | 203 +++++++++++++++++++++++
 9 files changed, 814 insertions(+)
 create mode 100755 2024-12-18/rectangle.php
 create mode 100755 2025-01-13/factoriel.php
 create mode 100755 2025-01-13/factoriel_tableau.php
 create mode 100755 2025-01-13/prime.php
 create mode 100755 2025-01-13/prime_hundred.php
 create mode 100755 2025-02-04/fibonacci.php
 create mode 100755 2025-02-04/rand_array.php
 create mode 100755 2025-03-14/oop_rand_array_to_file.php
 create mode 100755 2025-03-14/rand_array_to_file.php

diff --git a/2024-12-18/rectangle.php b/2024-12-18/rectangle.php
new file mode 100755
index 0000000..75e57c3
--- /dev/null
+++ b/2024-12-18/rectangle.php
@@ -0,0 +1,18 @@
+<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>
diff --git a/2025-01-13/factoriel.php b/2025-01-13/factoriel.php
new file mode 100755
index 0000000..fa51a12
--- /dev/null
+++ b/2025-01-13/factoriel.php
@@ -0,0 +1,25 @@
+<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/2025-01-13/factoriel_tableau.php b/2025-01-13/factoriel_tableau.php
new file mode 100755
index 0000000..4a718fc
--- /dev/null
+++ b/2025-01-13/factoriel_tableau.php
@@ -0,0 +1,32 @@
+<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/2025-01-13/prime.php b/2025-01-13/prime.php
new file mode 100755
index 0000000..15eeeeb
--- /dev/null
+++ b/2025-01-13/prime.php
@@ -0,0 +1,36 @@
+<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/2025-01-13/prime_hundred.php b/2025-01-13/prime_hundred.php
new file mode 100755
index 0000000..c930da1
--- /dev/null
+++ b/2025-01-13/prime_hundred.php
@@ -0,0 +1,28 @@
+<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/2025-02-04/fibonacci.php b/2025-02-04/fibonacci.php
new file mode 100755
index 0000000..f3ca578
--- /dev/null
+++ b/2025-02-04/fibonacci.php
@@ -0,0 +1,62 @@
+<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/2025-02-04/rand_array.php b/2025-02-04/rand_array.php
new file mode 100755
index 0000000..846ec74
--- /dev/null
+++ b/2025-02-04/rand_array.php
@@ -0,0 +1,183 @@
+<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/2025-03-14/oop_rand_array_to_file.php b/2025-03-14/oop_rand_array_to_file.php
new file mode 100755
index 0000000..6f2aac5
--- /dev/null
+++ b/2025-03-14/oop_rand_array_to_file.php
@@ -0,0 +1,227 @@
+<?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/2025-03-14/rand_array_to_file.php b/2025-03-14/rand_array_to_file.php
new file mode 100755
index 0000000..70f9ab8
--- /dev/null
+++ b/2025-03-14/rand_array_to_file.php
@@ -0,0 +1,203 @@
+<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
-- 
GitLab