SEND + MORE = MONEY: Difference between revisions

→‎{{header|Perl}}: added alternate approach
(→‎Raku:Fast: less verbose with junctions, but no loss of speed ('int' wasn't helping))
(→‎{{header|Perl}}: added alternate approach)
Line 691:
=={{header|Perl}}==
{{trans|Raku}}
=== Exhaustive ===
<syntaxhighlight lang="perl" line>use v5.36;
use enum <D E M N O R S Y>;
use Algorithm::Combinatorics <combinations permutations>;
 
sub solve {
for my $p (map { permutations $_ } combinations [0..9], 8) {
return $p if @$p[M] > 0 and join('',@$p[S,E,N,D])+join('',@$p[M,O,R,E]) == join('',@$p[M,O,N,E,Y]);
}
}
 
printf "SEND + MORE == MONEY\n%d + %d == %d", join('',@$_[S,E,N,D]), join('',@$_[M,O,R,E]), join '',@$_[M,O,N,E,Y]) for solve();</syntaxhighlight>
{{out}}
<pre>SEND + MORE == MONEY
9567 + 1085 == 10652</pre>
=== Fine-tuned ===
<syntaxhighlight lang="perl" line>use v5.36;
 
2,392

edits