Skip to content

Instantly share code, notes, and snippets.

@randrews
Created October 3, 2021 01:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randrews/7d68c281080608a893706478cc9b04d0 to your computer and use it in GitHub Desktop.
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.
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