aboutsummaryrefslogtreecommitdiff
path: root/sample/unary_numbers/hanoiSZ.in
diff options
context:
space:
mode:
Diffstat (limited to 'sample/unary_numbers/hanoiSZ.in')
-rw-r--r--sample/unary_numbers/hanoiSZ.in31
1 files changed, 31 insertions, 0 deletions
diff --git a/sample/unary_numbers/hanoiSZ.in b/sample/unary_numbers/hanoiSZ.in
new file mode 100644
index 0000000..a533d2d
--- /dev/null
+++ b/sample/unary_numbers/hanoiSZ.in
@@ -0,0 +1,31 @@
+// Tower of Hanoi Puzzle
+
+// Rules
+hanoi(return, source, target, aux) >< Z =>
+ // Erase the source, target and aux
+ source ~ Eraser,
+ target ~ Eraser,
+ aux ~ Eraser,
+
+ // result
+ return~[];
+
+hanoi(return, source, target, aux) >< S(n) =>
+ // Duplicate the source, target and aux
+ source ~ Dup(src1, Dup(src2, src3)),
+ target ~ Dup(tgt1, Dup(tgt2, tgt3)),
+ aux ~ Dup(aux1, aux2),
+
+
+ // recursive applications
+ n ~ Dup(nn1, Dup(nn2, nn3)),
+ hanoi(ret1, src1, aux1, tgt1)~nn1,
+ hanoi(ret2, aux2, tgt2, src2)~nn2,
+
+ // result
+ return << Append(ret1, (nn3,src3,tgt3):ret2);
+
+
+// Net
+hanoi(result, A, C, B) ~ S(S(S(Z)));
+result; \ No newline at end of file