Cryptarithmetic Solver - Problem
A cryptarithmetic puzzle is a mathematical equation where letters represent unique digits (0-9). Your task is to find the digit assignment that makes the equation valid.
Given a cryptarithmetic equation in the form WORD1 + WORD2 = RESULT, return a dictionary/map showing which digit each letter represents. If no valid solution exists, return an empty dictionary.
Rules:
- Each letter represents a unique digit (0-9)
- Leading letters cannot be 0 (e.g., in SEND, S ≠ 0)
- The equation must be mathematically correct
Input & Output
Example 1 — Classic SEND + MORE = MONEY
$
Input:
equation = "SEND + MORE = MONEY"
›
Output:
{"S":9,"E":5,"N":6,"D":7,"M":1,"O":0,"R":8,"Y":2}
💡 Note:
When S=9, E=5, N=6, D=7, M=1, O=0, R=8, Y=2, we get 9567 + 1085 = 10652, which is mathematically correct
Example 2 — Simple TWO + TWO = FOUR
$
Input:
equation = "TWO + TWO = FOUR"
›
Output:
{"T":7,"W":3,"O":4,"F":1,"U":9,"R":8}
💡 Note:
When T=7, W=3, O=4, F=1, U=9, R=8, we get 734 + 734 = 1468, which satisfies the equation
Example 3 — No Solution Case
$
Input:
equation = "ABC + DEF = GHI"
›
Output:
{}
💡 Note:
No valid digit assignment exists where a 3-digit + 3-digit = 3-digit with all different letters
Constraints
- Each letter represents a unique digit (0-9)
- Leading letters cannot be 0
- Equation contains 2-10 unique letters
- Input format: "WORD1 + WORD2 = RESULT"
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code