Skip to content

Instantly share code, notes, and snippets.

@mikedamage
Created May 3, 2015 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikedamage/b885d769d03e3079158c to your computer and use it in GitHub Desktop.
Save mikedamage/b885d769d03e3079158c to your computer and use it in GitHub Desktop.
Collatz Conjecture in JS
#!/usr/bin/env node
'use strict'
function collatz(num) {
var result;
if (num % 2 === 0) {
result = num / 2;
} else {
result = 3 * num + 1;
}
console.log(result);
if (result === 1) {
return;
}
collatz(result);
}
collatz(parseInt(process.argv[2], 10));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment