Skip to content

Instantly share code, notes, and snippets.

@jasonbellamy
Created November 16, 2016 12:19
Show Gist options
  • Save jasonbellamy/2a2eace1ba7576468324d7a415000b21 to your computer and use it in GitHub Desktop.
Save jasonbellamy/2a2eace1ba7576468324d7a415000b21 to your computer and use it in GitHub Desktop.
Recursive implementation of the Collatz conjecture
const collatz = (x, y = 0) => {
if (x === 1) {
return y;
}
return (x % 2) ? collatz((x * 3 + 1), y + 1) : collatz((x / 2), y + 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment