Collatz Conjecture
Uses the Collatz Conjecture to make any input go down to 1 with a formula
Uses the Collatz Conjecture to make any input go down to 1 with a formula
<?php
include('includes/header.php');
error_reporting(E_ALL); // Set error reporting to all
echo "<h1>Collatz Conjecture</h1>";
echo "<p>Uses the Collatz Conjecture to make any input go down to 1 with a formula";
// Check if the form was submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$i = $_POST['number'];
// Any number that is input becomes 1
echo("<p>$i</p>");
while ($i != 1){
if($i % 2 == 0){
echo("<p>$i /2=.</p>");
$i=$i/2;
}else{
echo("<p>$i x3+1=</p>");
$i=($i*3)+1;
}
echo("<p>$i</p>");
}
} {
echo '
<form method="post">
<label for="number">Enter a positive number:</label>
<input type="number" id="number" name="number" required>
<button type="submit">Generate numbers</button>
</form>';
}
include('includes/footer.php');
?>
<div id="home"><a href="https://citw.lcc.edu/~sperlt/citw185/index.php">Tedd Work</a></div>