Task

Solve the   Towers of Hanoi   problem with recursion.




sub hanoi(ndisks, startPeg, endPeg)
    if ndisks then
        hanoi(ndisks-1, startPeg, 6-startPeg-endPeg)
        //print "Move disk ", ndisks, " from ", startPeg, " to ", endPeg
        hanoi(ndisks-1, 6-startPeg-endPeg, endPeg)
    end if
end sub
 
print "Be patient, please.\n\n"
print "Hanoi 1 ellapsed ... ";
 
t1 = peek("millisrunning")
hanoi(22, 1, 3)
t2 = peek("millisrunning")
print t2-t1, " ms"
 
 
sub hanoi2(n, from, to_, via)
    if n = 1 then
	//print "Move from ", from, " to ", to_
    else
	hanoi2(n - 1, from, via , to_ )
    	hanoi2(1    , from, to_ , via )
    	hanoi2(n - 1, via , to_ , from)
    end if
end sub
 
print "Hanoi 2 ellapsed ... ";
hanoi2(22, 1, 3, 2)
print peek("millisrunning") - t2, " ms"