retroforth/example/hanoi.forth
crc 4044f88cfa towers of hanoi; better variable naming
FossilOrigin-Name: dcbc4dc52e45f686490ce8d4c4e9b5cd9ffbbf2fad7e76ab5a2faff5023fa498
2017-10-22 17:45:28 +00:00

20 lines
340 B
Forth

~~~
'Num var
'From var
'To var
'Via var
:set-vars !Via !To !From !Num ;
:hanoi (num,from,to,via-)
set-vars
@Num n:-zero?
[
@Num @From @To @Via
@Num n:dec @From @Via @To hanoi
set-vars
@To @From '\nMove_a_ring_from_%n_to_%n s:with-format puts
@Num n:dec @Via @To @From hanoi
] if ;
#3 #1 #3 #2 hanoi nl
~~~