SEND + MORE = MONEY: Difference between revisions
Content added Content deleted
(→{{header|Wren}}: A bit simpler and quicker.) |
(julia example) |
||
Line 2: | Line 2: | ||
Write a program in your language to solve [https://mindyourdecisions.com/blog/2018/09/06/send-more-money-a-great-puzzle/ SEND + MORE = MONEY: A Great Puzzle]. |
Write a program in your language to solve [https://mindyourdecisions.com/blog/2018/09/06/send-more-money-a-great-puzzle/ SEND + MORE = MONEY: A Great Puzzle]. |
||
<br> |
<br> |
||
=={{header|Julia}}== |
|||
A hoary old talk, solved with pencil before electricity was a thing. |
|||
Since the M in Money is the result of carry in base 10 of two single digits it is a 1 (we exclude 0 here though that would work, but then MONEY would be spelled ONEY). |
|||
In addition, the S plus 1 then needs to result in a carry, so S is 8 or 9, depending on whether there is a carry into that column. Onw can continue, but from here the computer is likely quicker. |
|||
<syntaxhighlight lang="julia">let |
|||
m = 1 |
|||
for s in 8:9 |
|||
for e in 0:9 |
|||
e in [m, s] && continue |
|||
for n in 0:9 |
|||
n in [m, s, e] && continue |
|||
for d in 0:9 |
|||
d in [m, s, e, n] && continue |
|||
for o in 0:9 |
|||
o in [m, s, e, n, d] && continue |
|||
for r in 0:9 |
|||
r in [m, s, e, n, d, o] && continue |
|||
for y in 0:9 |
|||
y in [m, s, e, n, d, o] && continue |
|||
if 1000s + 100e + 10n + d + 1000m + 100o + 10r + e == |
|||
10000m + 1000o + 100n + 10e + y |
|||
println("$s$e$n$d + $m$o$r$e == $m$o$n$e$y") |
|||
end |
|||
end |
|||
end |
|||
end |
|||
end |
|||
end |
|||
end |
|||
end |
|||
end |
|||
</syntaxhighlight>{{out}} 9567 + 1085 == 10652 |
|||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
<syntaxhighlight lang="ring"> |
<syntaxhighlight lang="ring"> |