Last active
August 29, 2019 21:12
-
-
Save ashearer/06532783f85374de6960b6ce26c7f248 to your computer and use it in GitHub Desktop.
Alphametic puzzle brute force
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
#!python | |
from itertools import permutations | |
def num(format, vals): | |
return int("".join(str(vals[letter]) for letter in format)) | |
letters = "eightrnwy " | |
def to_indices(word): | |
return [letters.find(letter) for letter in word] | |
eight = to_indices("eight") | |
three = to_indices("three") | |
nine = to_indices("nine") | |
twenty = to_indices("twenty") | |
for a in permutations(range(10)): | |
if num(eight, a) + num(three, a) + num(nine, a) == num(twenty, a): | |
print dict(zip(letters, a)) | |
print num(eight, a), "+", num(three, a), "+", num(nine, a), "=", num(twenty, a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The puzzle:
What numerical value does each letter represent?