Created
January 7, 2020 16:25
-
-
Save wertlex/d03a8728b73d7162f0fb60960848d01f 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
// https://en.wikipedia.org/wiki/Collatz_conjecture | |
function collatzStep(n: number): number { | |
if (n % 2 === 0) { | |
return n/2; | |
} else { | |
return (n * 3) + 1; | |
} | |
} | |
let i: number = 1; | |
let n: number = 3; // number to start with | |
console.log(`${i}: ${n}`); | |
while (true) { | |
n = collatzStep(n); | |
console.log(`${i}: ${n}`); | |
i++; | |
if (n === 1) { | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment