Dinesman's multiple-dwelling problem: Difference between revisions
Content deleted Content added
m →{{header|Perl 6}}: Change adjacency expression |
→{{header|Perl 6}}: various simplifications |
||
Line 296:
=={{header|Perl 6}}==
We use permutations because "different floors" are specified. The next_perm subroutine is a variant of the one from the [[Permutations]] task.
<lang perl6>sub next_perm ( @a is copy ) {
my $j = @a.end - 1;
my $aj = @a[$j];
my $k = @a.end;
$k-- while [
@a[ $j, $k ] .= reverse;
my
my
@a[ $r--, $s++ ] .= reverse while $r > $s
return @a;
}
# Contains only five floors. 5! = 120 permutations.
for
say "Baker=$b Cooper=$c Fletcher=$f Miller=$m Smith=$s"
if $b != 5 # Baker !live on top floor.
|