24 game/Solve: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (Automated syntax highlighting fixup (second round - minor fixes)) |
SqrtNegInf (talk | contribs) m (→Raku: replace odd syntax in 'roundrobin') |
||
Line 7,602: | Line 7,602: | ||
# Brute force test the different permutations |
# Brute force test the different permutations |
||
@digits.permutations».join.unique».comb.race.map: -> @p { |
|||
for @ops -> @o { |
for @ops -> @o { |
||
for @formats -> $format { |
for @formats -> $format { |
||
my $string = sprintf $format, |
my $result = .EVAL given my $string = sprintf $format, roundrobin(@p, @o, :slip); |
||
my $result = EVAL($string); |
|||
say "$string = 24" and last if $result and $result == 24; |
say "$string = 24" and last if $result and $result == 24; |
||
} |
} |
||
} |
} |
||
} |
} |
||
# Only return unique sub-arrays |
|||
sub unique (@array) { |
|||
my %h = map { $_.Str => $_ }, @array; |
|||
%h.values; |
|||
}</syntaxhighlight> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |