Zebra puzzle: Difference between revisions
Content deleted Content added
→{{header|Perl 6}}: a bit more gather/take |
|||
Line 4,923: | Line 4,923: | ||
multi sub solve(@houses, @facts is copy) { |
multi sub solve(@houses, @facts is copy) { |
||
my $fact = @facts.shift; |
my $fact = @facts.shift; |
||
for gather |
for gather consider(@houses, |$fact) { |
||
solve(@$_, @facts) |
solve(@$_, @facts) |
||
} |
} |
||
Line 4,930: | Line 4,930: | ||
#| find all possible solutions for pairs of houses with |
#| find all possible solutions for pairs of houses with |
||
#| %a attributes, left of a house with %b attributes |
#| %a attributes, left of a house with %b attributes |
||
multi sub |
multi sub consider(@houses, :Left-Of(%b)!, *%a) { |
||
my @scenarios; |
my @scenarios; |
||
for @houses { |
for @houses { |
||
Line 4,945: | Line 4,945: | ||
#| find all possible pairs of houses with %a attributes, either side |
#| find all possible pairs of houses with %a attributes, either side |
||
#! of a house with %b attributes |
#! of a house with %b attributes |
||
multi sub |
multi sub consider(@houses, :Next-To(%b)!, *%a ) { |
||
consider(@houses, |%a, :Left-Of(%b) ); |
|||
consider(@houses, |%b, :Left-Of(%a) ); |
|||
} |
} |
||
#| find all possible houses that match the given attributes |
#| find all possible houses that match the given attributes |
||
multi sub |
multi sub consider(@houses, *%fact) { |
||
for @houses.grep({plausible($_, %fact)}) -> $house { |
for @houses.grep({plausible($_, %fact)}) -> $house { |
||
my @scenario = @houses.clone; |
my @scenario = @houses.clone; |