Skip to content

Instantly share code, notes, and snippets.

@khanghoang
Created December 30, 2015 03:40
Show Gist options
  • Save khanghoang/995bf55518850491f143 to your computer and use it in GitHub Desktop.
Save khanghoang/995bf55518850491f143 to your computer and use it in GitHub Desktop.
squirrel's business
function isInt(n){
return Number(n) === n && n % 1 === 0;
}
function test(x) {
// x is the number that the last squirrel takes
return x * 5 + 1;
}
function thePreviousNuts(x) {
return x / 4 * 5 + 1;
}
var i = 1;
while (i < 1000) {
var temp = test(i);
for (var y = 1; y <= 4; y++) {
temp = thePreviousNuts(temp);
// console.log('y = ', y, 'temp =', temp);
if (!isInt(temp)) {
break;
}
if (y === 4) {
console.log(temp);
console.log(i);
i = 1001;
}
}
i += 1;
}
console.log('done');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment