All pastes #1327873 Raw Edit

Untitled

public text v1 · immutable
#1327873 ·published 2009-02-05 10:27 UTC
rendered paste body
sub hanoi {
	my ($n, $start, $end, $extra, $move_disk) = @_;
	if ($n == 1) {
		$move_disk->(1, $start, $end);
	} else {
		hanoi($n-1, $start, $extra, $end);
		$move_disk->($n, $start, $end);
		hanoi($n-1, $extra, $end, $start);
	}
}
sub print_instruction {
	my ($disk, $start, $end) = @_;	
	print "Move disk #$disk from $start to $end.\n";
}
hanoi(3, 'A', 'C', 'B', \&print_instruction);