From 4b5967cf5d9a0027a1daff08f33e80d587fbb0c1 Mon Sep 17 00:00:00 2001 From: crc Date: Fri, 20 Oct 2017 19:58:42 +0000 Subject: [PATCH] towers of hanoi solver FossilOrigin-Name: 27e9fbb70fc8c2dce373b7255089083ddb5687c0dd893a5d9f10ac06e304e807 --- example/hanoi.forth | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 example/hanoi.forth diff --git a/example/hanoi.forth b/example/hanoi.forth new file mode 100644 index 0000000..a40eb09 --- /dev/null +++ b/example/hanoi.forth @@ -0,0 +1,20 @@ +~~~ +'a var +'b var +'c var +'n var + +:vars !c !b !a !n ; +:hanoi (num,from,to,via-) + vars + @n n:-zero? + [ + @n @a @b @c + @n n:dec @a @c @b hanoi + vars + @b @a '\nMove_a_ring_from_%n_to_%n s:with-format puts + @n n:dec @c @b @a hanoi + ] if ; + +#5 #1 #3 #2 hanoi nl +~~~