SEND + MORE = MONEY: Difference between revisions
→Raku:Fast: less verbose with junctions, but no loss of speed ('int' wasn't helping)
SqrtNegInf (talk | contribs) (Added Perl) |
SqrtNegInf (talk | contribs) (→Raku:Fast: less verbose with junctions, but no loss of speed ('int' wasn't helping)) |
||
Line 901:
=== 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 speedy. Applying the observation that M must be 1 and S must be either 8 or 9 gets the runtime under a tenth of a second.
<syntaxhighlight lang="raku" line>my
while ++$s
my int $e = -1;▼
▲ while ++$e <= 9 {
next if $e == $s;
next if $
while ++$
next if $
▲ next if $d == $e;
next if $y == $s|$e|$n|$d|$m|$o|$r;▼
▲ my int $o = -1;
▲ while ++$o <= 9 {
▲ next if $o == $s;
▲ while ++$r <= 9 {
▲ my int $y = -1;
▲ next if $y == $s;
my
next unless $send + $more == $money;
say 'SEND + MORE == MONEY' ~ "\n$send + $more == $money";
}
}
|