Skip to content

Instantly share code, notes, and snippets.

@pragdave
Created September 23, 2019 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pragdave/42aeea278c510aafe8feaee0ca4096f4 to your computer and use it in GitHub Desktop.
Save pragdave/42aeea278c510aafe8feaee0ca4096f4 to your computer and use it in GitHub Desktop.
naive implementation of the cryptoarithmetic puzzle SEND + MORE = MONEY
-- Solve SEND + MORE = MONEY
select S.i, E.i, N.i, D.i, M.i, O.i, R.i, Y.i
from digits S, digits E, digits N, digits D,
digits M, digits O, digits R, digits Y
where S.i != 0
and M.i = 1
and (S.i + M.i)*1000 + (E.i + O.i)*100 + (N.i + R.i)*10 + D.i + E.i
= M.i*10000 + O.i*1000 + N.i*100 + E.i*10 + Y.i
and S.i not in ( E.i, N.i, D.i, M.i, O.i, R.i, Y.i)
and E.i not in ( N.i, D.i, M.i, O.i, R.i, Y.i)
and N.i not in ( D.i, M.i, O.i, R.i, Y.i)
and D.i not in ( M.i, O.i, R.i, Y.i)
and M.i not in ( O.i, R.i, Y.i)
and O.i not in ( R.i, Y.i)
and R.i != Y.i;
@andyl
Copy link

andyl commented Sep 23, 2019

LOL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment