-
-
Save ageldama/6814c611b5bd09165a9499b91917c84a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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