Created
April 2, 2017 18:27
-
-
Save lykkin/76c8bd5ea76fe9934287d310c87b4e61 to your computer and use it in GitHub Desktop.
This file contains 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
function collatz(n) { | |
var chain = [n] | |
while (n !== 1) { | |
if (n % 2 === 0) { | |
n /= 2 | |
} else { | |
n = n * 3 + 1 | |
} | |
chain.push(n) | |
} | |
chain.push(1) | |
return chain | |
} | |
Array.apply(null, Array(1000)).map(function(x, i) {return collatz(i + 1)}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment