Skip to content

Instantly share code, notes, and snippets.

@dotslashf
Created April 5, 2022 02:04
Show Gist options
  • Save dotslashf/84f631ac811c5f54ac182a34c2aa253d to your computer and use it in GitHub Desktop.
Save dotslashf/84f631ac811c5f54ac182a34c2aa253d to your computer and use it in GitHub Desktop.
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