Created
March 31, 2010 14:27
-
-
Save weatheredwatcher/350387 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
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; | |
} | |
collatz(n, counter); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment