summaryrefslogtreecommitdiff
path: root/miralib/ex/hanoi.m
diff options
context:
space:
mode:
Diffstat (limited to 'miralib/ex/hanoi.m')
-rw-r--r--miralib/ex/hanoi.m11
1 files changed, 11 insertions, 0 deletions
diff --git a/miralib/ex/hanoi.m b/miralib/ex/hanoi.m
new file mode 100644
index 0000000..b927ca3
--- /dev/null
+++ b/miralib/ex/hanoi.m
@@ -0,0 +1,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"