Created
April 5, 2022 02:04
-
-
Save dotslashf/84f631ac811c5f54ac182a34c2aa253d 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
| function collatzConjecture(num) { | |
| if (num % 2 === 0) { | |
| return num / 2; | |
| } else if (num % 2 === 1) { | |
| return num * 3 + 1; | |
| } else if (num === 1) { | |
| return 1; | |
| } | |
| } | |
| function main() { | |
| let seed = 9; | |
| let result = []; | |
| while (seed !== 1) { | |
| result.push(seed); | |
| seed = collatzConjecture(seed); | |
| } | |
| result.push(1); | |
| console.log(result); | |
| } | |
| main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment