Last active
June 5, 2017 01:28
-
-
Save erikzrekz/ffcfae325eae4b02e77df39caf9a19ef to your computer and use it in GitHub Desktop.
An algorithm that gives you the number of steps it takes n to be 1 — the 3x+1 problem.
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
var x = 0; | |
var n = 1988; | |
do { | |
if (n % 2 == 0) { | |
n = n / 2; | |
} else { | |
n = (3 * n) + 1; | |
} | |
x++; | |
console.log(x); | |
} | |
while(n > 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment