SEND + MORE = MONEY: Difference between revisions
Content added Content deleted
(→{{header|Raku}}: Added Raku solution) |
Thundergnat (talk | contribs) m (→{{header|Raku}}: Add an alternate) |
||
Line 89: | Line 89: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
=== Idiomatic === |
|||
<syntaxhighlight lang="raku" line> |
<syntaxhighlight lang="raku" line> |
||
enum <D E M N O R S Y>; |
enum <D E M N O R S Y>; |
||
Line 115: | Line 116: | ||
== 10652 |
== 10652 |
||
</pre> |
</pre> |
||
=== Fast === |
|||
Alternately, a version written in 2015 by [http://strangelyconsistent.org/blog/send-more-money-in-perl6 Carl Mäsak]. Not very concise but quite fast. |
|||
=={{header|Raku}}== |
|||
<syntaxhighlight lang="raku" line>my int $s = -1; |
|||
while ++$s <= 9 { |
|||
next if $s == 0; |
|||
my int $e = -1; |
|||
while ++$e <= 9 { |
|||
next if $e == $s; |
|||
my int $n = -1; |
|||
while ++$n <= 9 { |
|||
next if $n == $s; |
|||
next if $n == $e; |
|||
my int $d = -1; |
|||
while ++$d <= 9 { |
|||
next if $d == $s; |
|||
next if $d == $e; |
|||
next if $d == $n; |
|||
my int $send = $s*1000 + $e*100 + $n*10 + $d; |
|||
my int $m = -1; |
|||
while ++$m <= 9 { |
|||
next if $m == 0; |
|||
next if $m == $s; |
|||
next if $m == $e; |
|||
next if $m == $n; |
|||
next if $m == $d; |
|||
my int $o = -1; |
|||
while ++$o <= 9 { |
|||
next if $o == $s; |
|||
next if $o == $e; |
|||
next if $o == $n; |
|||
next if $o == $d; |
|||
next if $o == $m; |
|||
my int $r = -1; |
|||
while ++$r <= 9 { |
|||
next if $r == $s; |
|||
next if $r == $e; |
|||
next if $r == $n; |
|||
next if $r == $d; |
|||
next if $r == $m; |
|||
next if $r == $o; |
|||
my int $more = $m*1000 + $o*100 + $r*10 + $e; |
|||
my int $y = -1; |
|||
while ++$y <= 9 { |
|||
next if $y == $s; |
|||
next if $y == $e; |
|||
next if $y == $n; |
|||
next if $y == $d; |
|||
next if $y == $m; |
|||
next if $y == $o; |
|||
next if $y == $r; |
|||
my int $money = |
|||
$m*10000 + $o*1000 + $n*100 + $e*10 + $y; |
|||
next unless $send + $more == $money; |
|||
say 'SEND + MORE == MONEY'; |
|||
say "$send + $more == $money"; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
}</syntaxhighlight> |
|||
{{out}} |
|||
<pre>SEND + MORE == MONEY |
|||
9567 + 1085 == 10652</pre> |
|||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
<syntaxhighlight lang="ring"> |
<syntaxhighlight lang="ring"> |