Skip to content

Instantly share code, notes, and snippets.

@ageldama
Forked from sairion/boooooooo.js
Created July 6, 2016 17:46
Show Gist options
  • Save ageldama/6814c611b5bd09165a9499b91917c84a to your computer and use it in GitHub Desktop.
Save ageldama/6814c611b5bd09165a9499b91917c84a to your computer and use it in GitHub Desktop.
function pp(givenNth, curNth = 0, dir = 1 /* { 1, -1 } */, result = 0) {
// console.log(isTurnAround(curNth + 1), arguments[0], arguments[1], arguments[2], arguments[3]);
if (givenNth === curNth) {
return result;
} else {
// if (isTurnAround(curNth + 1) === -1) { console.log('Turnaround desune ^ * ^'); }
return pp(givenNth, curNth + 1, isTurnAround(curNth + 1) * dir, result + dir);
}
}
function isTurnAround(n) {
if (n > 0) {
if (n % 7 === 0 || String(n).indexOf('7') > -1) {
return -1;
}
}
return 1;
}
console.assert(pp(8) === 6);
console.assert(pp(22) === 0);
console.assert(pp(68) === 2);
console.assert(pp(100) === 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment