Skip to content

Instantly share code, notes, and snippets.

@erikzrekz
Last active June 5, 2017 01:28
Show Gist options
  • Save erikzrekz/ffcfae325eae4b02e77df39caf9a19ef to your computer and use it in GitHub Desktop.
Save erikzrekz/ffcfae325eae4b02e77df39caf9a19ef to your computer and use it in GitHub Desktop.
An algorithm that gives you the number of steps it takes n to be 1 — the 3x+1 problem.
var x = 0;
var n = 1988;
do {
if (n % 2 == 0) {
n = n / 2;
} else {
n = (3 * n) + 1;
}
x++;
console.log(x);
}
while(n > 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment