Anonymous user
Zebra puzzle: Difference between revisions
→{{header|Raku}}: Make use of temp over clone. Variable renaming.
(add mercury) |
(→{{header|Raku}}: Make use of temp over clone. Variable renaming.) |
||
Line 6,060:
for gather solve(@houses, @facts) {
#-- output
say .
say
for .list;
last; # stop after first solution
Line 6,067:
}
#|
multi sub solve(@solution, @facts [ ]) {
take @solution;
}
#| extend
multi sub solve(@scenario, [ $fact, *@facts ] is copy) {
for gather
solve(@
}
}
#| find all possible solutions for pairs of houses with
#| lemma %a
multi sub
for @houses {
my $idx = .<num> - 1;
if $idx > 0 && plausible(@houses[$idx-1], %a) && plausible(@houses[$idx], %b) {
}
}
}
#| suppose these houses are next to each other (left or right)
multi sub suppose(@houses, :Next-To(%b)!, *%a ) {
}
#| find all possible houses that match the given attributes
multi sub
for @houses.grep({plausible($_, %
my $idx = $house<num> - 1;
temp @
take @
}
}
#| plausible if doesn't conflict with anything
sub plausible(%house, %
}
</lang>
|