Skip to content

Instantly share code, notes, and snippets.

@T0071
Created March 15, 2017 06:52
Show Gist options
  • Save T0071/c826bf85a4f204d477307c3098a09716 to your computer and use it in GitHub Desktop.
Save T0071/c826bf85a4f204d477307c3098a09716 to your computer and use it in GitHub Desktop.
collatz conjecture
function isEven(a) {
a = Number(a);
return a === 0 || !!(a && !(a%2));
}
// Write a Function for the conjecture
function collatz(n){
const number = n;
let counter = 0;
while(n != 1){
counter += 1;
// Condition
if(isEven(n) === true){
n = n * 0.5;
}else if(n === 1){
break;
}
else{
n = n * 3 + 1;
}
}
console.log(number + "=>" + counter);
}
@CodeEpendent
Copy link

sidesync_capture_20160730141228_1

@CodeEpendent
Copy link

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment