This is the Tower of Hanoi.
It displays the solution method of the Tower of Hanoi.
It is often used as an example of a recursive call.
See also here about "Tower of Hanoi".
https://en.wikipedia.org/wiki/Tower_of_Hanoi
/* Tower of Hanoi for X68
// Oh!X 1988/5 p54
int n
str a="A",b="B",c="C"
while 1
input "n(0=end)=" , n
if n=0 then break
hanoi( n , a ,c , b)
print
endwhile
end
func hanoi(n;int,a;str,c;str,b;str)
if n>0 then {
hanoi(n-1,a,b,c)
print a; "->" ; c; ",";
hanoi(n-1,b,c,a)
}
endfunc
No comments:
Post a Comment