OraQA

Oracle Question and Answer

  • Do you have a solution to a problem? Do you have an unanswered question? Login and share it with the Oracle community. More...

Oracle News


Entries RSS feed

Comments RSS feed

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

Leave a Reply

You must be logged in to post a comment.

RSS feed for comments on this question