summaryrefslogtreecommitdiff
path: root/miralib/ex/hanoi.m
blob: b927ca31766eb3224c98799df2ac958682f18024 (plain)
1
2
3
4
5
6
7
8
9
10
11
||This script generates a solution to the well known `Towers of Hanoi'
||problem.  To see the moves (for a game with 12 discs) say
||	soln

soln = title++hanoi 12 "A" "B" "C"
title = "SOLUTION TO TOWERS OF HANOI WITH 8 DISCS\n\n"
hanoi 0 a b c = [] 
hanoi (n+1) a b c = hanoi n a c b
	            ++ move a b ++
	            hanoi n c b a
move a b = "move the top disc from "++a++" to "++b++"\n"