addends are added together and their sum is the word total. Every word is written in uppercase English letters.
Replace every letter with a digit from 0 to 9 so that:
- the same letter always gets the same digit and different letters get different digits;
- no word of two or more letters starts with zero (a one-letter word may be zero);
- the numbers from addends add up to the number total.
There are only ten digits, so a puzzle with more than ten distinct letters has no solution.
Return True if such a replacement exists and False otherwise.addends=['TO', 'GO'], total='OUT' → True
T = 2, O = 1, G = 8, U = 0 works: 21 + 81 = 102.
addends=['AB', 'AB'], total='AB' → False
AB + AB = AB forces AB = 0, but a two-digit number cannot start with zero.
addends=['A', 'B'], total='A' → True
Take B = 0 and any other digit for A: a one-letter word may stand for zero.
addends.length ≤ 5addends[i].length, total.length ≤ 11addends=['TO', 'GO'], total='OUT'
True
Run checks the first 3 tests in your browser. Submit checks all 150 tests on the server, hidden ones included.