Towers of Hanoi: Difference between revisions

Perl 5: Changed to permit calling with one argument. Perl 6: Added.
(Perl 5: Changed to permit calling with one argument. Perl 6: Added.)
Line 680:
 
=={{header|Perl}}==
<lang perl> sub movehanoi {
my ($n, $from, $to, $via) = (@_, 1, 2, 3);
 
if ($n == 1) {
print "Move disk from pole $from to pole $to.\n";
} else {
movehanoi($n - 1, $from, $via, $to);
movehanoi(1, $from, $to, $via);
movehanoi($n - 1, $via, $to, $from);
};
};</lang>
 
=={{header|Perl 6}}==
{{works with|Rakudo|#22 "Thousand Oaks"}}
 
<lang perl6>subset Peg of Int where * == 1|2|3;
 
multi hanoi (0, Peg $a, Peg $b, Peg $c) { }
multi hanoi (Int $n, Peg $a = 1, Peg $b = 2, Peg $c = 3) {
hanoi $n - 1, $a, $c, $b;
say "Move $a to $b.";
hanoi $n - 1, $c, $b, $a;
}</lang>
 
=={{header|PHP}}==
845

edits