How to solve the Cryptarithm: A + HA = HEE puzzle in SQL
November 7th, 2007 By Frank Zhou
The following is an interesting puzzle posted on the Interactive Mathematics Miscellany and Puzzles:
In the addition problem below, different letters stand for different digits. AH represents a two-digit number and HEE represents a three-digit number. What number does HEE represent?
A H
+ A
———
H E E
———————–SQL Solution————-
SELECT H.n||E.n||E.n as H_E_E FROM (SELECT LEVEL-1 n FROM DUAL CONNECT BY LEVEL <=10) A, (SELECT LEVEL-1 n FROM DUAL CONNECT BY LEVEL <=10) H, (SELECT LEVEL-1 n FROM DUAL CONNECT BY LEVEL <=10) E WHERE A.n NOT IN (H.n, E.n) AND H.n NOT IN (A.n, E.n) AND E.n NOT IN (A.n, H.n) AND mod(H.n + A.n - E.n, 10) = 0 AND mod(A.n + trunc((H.n + A.n - E.n)/10)- E.n, 10) = 0 AND trunc((A.n + trunc((H.n + A.n - E.n)/10) - E.n)/10) = H.n H_E_E ----------------------------------- 100 Elapsed: 00:00:00.15
