Created
October 3, 2021 01:14
-
-
Save randrews/7d68c281080608a893706478cc9b04d0 to your computer and use it in GitHub Desktop.
Adam's puzzle, the puzzle from Adam, the puzzle made specifically by Adam, that puzzle.
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
const toNum = digits => Number.parseInt(digits.join('')) | |
const valid = digits => toNum(digits) % digits.length === 0 | |
function solve(digits = []) { | |
if (digits.length === 9) { return toNum([...digits, 0]) } | |
for(var i = 1; i <= 9; i++) { | |
if (digits.indexOf(i) >= 0) { continue } | |
if (valid([...digits, i])) { | |
const soln = solve([...digits, i]) | |
if (soln) { return soln } | |
} | |
} | |
} | |
document.write(solve()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment