Cryptarithmetic Puzzle

Cryptarithmetic Puzzle

This is a mission to create a solver for the cryptarithmetic puzzle. In this puzzle, each letter must be assigned a one-digit number to complete the calculation.

You are given a list of words. The last word is the sum. You have to return a dictionary with the alphabets as keys and the one-digit numbers as values.

NOTE:

  • Each letter should represent a different digit.
  • The leading digit of a multi-digit number must not be zero.
  • All tests always have one answer.

Examples:

example_01 example_02

assert cryptarithm_solver(['SEND', 'MORE', 'MONEY']) == {'S': 9, 'E': 5, 'N': 6, 'D': 7, 'M': 1, 'O': 0, 'R': 8, 'Y': 2}
assert cryptarithm_solver(['SIX', 'SEVEN', 'SEVEN', 'TWENTY']) == {'Y': 4, 'X': 0, 'N': 2, 'I': 5, 'E': 8, 'T': 1, 'S': 6, 'V': 7, 'W': 3}

Input: The list of words (A list of string)

Output: The dictionary that the alphabets corresponds to the one-digit numbers (A dictionary)

Precondition:

  • len(words) <= 10