24 game/Solve: Difference between revisions

Content added Content deleted
m (Automated syntax highlighting fixup (second round - minor fixes))
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
(unique @digits.permutations).race.map: -> @p {
@digits.permutations».join.unique».comb.race.map: -> @p {
for @ops -> @o {
for @ops -> @o {
for @formats -> $format {
for @formats -> $format {
my $string = sprintf $format, flat roundrobin(|@p; |@o);
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>