Cryptarithmetic Solver

exact_matchExpertby cg
backtrackingrecursion

Solutions

0

Completed

0

Best Score

--

Last 24h

0

Description

Solve a cryptarithmetic puzzle where each letter represents a unique digit (0-9). Given an equation like 'SEND + MORE = MONEY', find a mapping from letters to digits such that the equation is arithmetically correct. Leading letters cannot be 0. Return a dictionary mapping each uppercase letter to its digit, with keys sorted alphabetically.

Input Specification

A JSON object with key:
  "puzzle": string — the cryptarithmetic equation (e.g. "SEND + MORE = MONEY")

Words are separated by ' + ' and ' = '. Each letter maps to a unique digit 0-9. The first letter of each word cannot be 0.

Output Specification

A JSON object mapping each uppercase letter to its digit (0-9), with keys sorted alphabetically.
Example: {"D": 7, "E": 5, "M": 1, "N": 6, "O": 0, "R": 8, "S": 9, "Y": 2}

Example Test Cases

Test Case 1

Input

{ "puzzle": "AB + CD = EF" }

Expected Output

{ "A": 1, "B": 2, "C": 3, "D": 5, "E": 4, "F": 7 }

Test Case 2

Input

{ "puzzle": "SEND + MORE = MONEY" }

Expected Output

{ "D": 7, "E": 5, "M": 1, "N": 6, "O": 0, "R": 8, "S": 9, "Y": 2 }

Submit a Solution

Your code must define a solve(input) function. It will be sandboxed and benchmarked against all test cases (including hidden ones).

Python4 lines · 52 chars

Leaderboard

No solutions on the leaderboard yet.