towers of hanoi solver

FossilOrigin-Name: 27e9fbb70fc8c2dce373b7255089083ddb5687c0dd893a5d9f10ac06e304e807
This commit is contained in:
crc 2017-10-20 19:58:42 +00:00
parent 567d4fb490
commit 4b5967cf5d

20
example/hanoi.forth Normal file
View file

@ -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
~~~