...

/

Cryptic Math Equation (Backtracking)

Cryptic Math Equation (Backtracking)

Solidify your analytical skills by solving a cryptic math equation using backtracking.

Problem

We want to solve this cryptic equation. Each letter stands for a unique digit (0–9). There are no leading zeros. Write a program that finds a numeric assignment to the letters for which the given equation is satisfied.

UK
USA
+ USSR
--------
AGING
Cryptic equation example

Purpose

  • Backtracking to solve number puzzles

Analyze

  • The brute-force approach by nesting loops will work for this puzzle, but won’t be elegant. We could use backtracking to solve this puzzle instead.

  • We have 8 letters here—U, K, S, A, R, G, I, and N.

  • For each letter, possible values are 0–9. So, our backtracking algorithm can be as follows:

    • Starting with the first letter U, ...