Created
June 26, 2012 04:54
-
-
Save yesidays/2993382 to your computer and use it in GitHub Desktop.
Algoritmo de Collatz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form id="form1" name="form1" method="post" action=""> | |
<table width="331" border="0"> | |
<tr> <td width="124">Ingrese el número</td> | |
<td width="197"><input type="text" name="numero" id="numero" /></td> | |
</tr> | |
<tr> <td><input type="submit" name="baceptar" id="baceptar" value="Generar" /> </td></tr> | |
</table> | |
<? if ($_REQUEST['baceptar']!= ""){ | |
if ($_REQUEST["numero"] != "") { | |
$resultado = $_REQUEST['numero']; | |
echo "<b>".$numero."</b><br />"; | |
$pasos = 1; | |
while ($resultado != 1){ | |
if ($resultado%2==0){ | |
$total = $resultado / 2; | |
$resultado = $total; | |
echo $resultado."<br />"; | |
} | |
else{ | |
$total = ($resultado * 3) + 1; | |
$resultado = $total; | |
echo $resultado."<br />"; | |
} | |
$pasos++; | |
} | |
} | |
} | |
echo "<br />Número total de pasos: <b>".$pasos."</b>"; | |
?> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment