Created
March 31, 2010 14:30
-
-
Save weatheredwatcher/350392 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" | |
"http://www.w3.org/TR/html4/strict.dtd" > | |
<html lang = "en" > | |
<head> | |
<meta http - equiv = "Content-Type"content = "text/html; charset=utf-8" > | |
<title > Collatz Conjecture </title> | |
<meta name="generator" content="TextMate http:/ / macromates.com / "> | |
<meta name="author " content="weatheredwatcher "> | |
<!-- Date: 2010-03-07 --> | |
<script> | |
n = prompt("Enter a number greater than 1: "); | |
var counter = 0 | |
function collatz(n, counter) { | |
document.display.myCounter.value=counter; | |
if (n>1) { | |
if (n%2) { | |
t = 3 * n + 1; | |
counter++; | |
collatz(t, counter); | |
} else{ | |
t = n/2; | |
counter++; | |
collatz(t, counter); | |
}; | |
}; | |
return counter; | |
} | |
</script> | |
</head> | |
<body> | |
<div> | |
<form name="display"> | |
<input type="text" name="myCounter" value="0" /> | |
</form> | |
<script> | |
collatz(n, counter); | |
</script> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment