Towers of Hanoi: Difference between revisions
Content added Content deleted
No edit summary |
(→{{header|Dc}}: The content is under BSD license, I have listed the source.) |
||
Line 141: | Line 141: | ||
Hanoi(n, "L","M","R") ; |
Hanoi(n, "L","M","R") ; |
||
}</pre> |
}</pre> |
||
=={{header|Dc}}== |
|||
From [http://se.aminet.net/pub/OpenBSD/src/regress/usr.bin/dc/t20.in Here] |
|||
<pre> |
|||
[ # move(from, to) |
|||
n # print from |
|||
[ --> ]n # print " --> " |
|||
p # print to\n |
|||
sw # p doesn't pop, so get rid of the value |
|||
]sm |
|||
[ # init(n) |
|||
sw # tuck n away temporarily |
|||
9 # sentinel as bottom of stack |
|||
lw # bring n back |
|||
1 # "from" tower's label |
|||
3 # "to" tower's label |
|||
0 # processed marker |
|||
]si |
|||
[ # Move() |
|||
lt # push to |
|||
lf # push from |
|||
lmx # call move(from, to) |
|||
]sM |
|||
[ # code block <d> |
|||
ln # push n |
|||
lf # push from |
|||
lt # push to |
|||
1 # push processed marker 1 |
|||
ln # push n |
|||
1 # push 1 |
|||
- # n - 1 |
|||
lf # push from |
|||
ll # push left |
|||
0 # push processed marker 0 |
|||
]sd |
|||
[ # code block <e> |
|||
ln # push n |
|||
1 # push 1 |
|||
- # n - 1 |
|||
ll # push left |
|||
lt # push to |
|||
0 # push processed marker 0 |
|||
]se |
|||
[ # code block <x> |
|||
ln 1 =M |
|||
ln 1 !=d |
|||
]sx |
|||
[ # code block <y> |
|||
lMx |
|||
lex |
|||
]sy |
|||
[ # quit() |
|||
q # exit the program |
|||
]sq |
|||
[ # run() |
|||
d 9 =q # if stack empty, quit() |
|||
sp # processed |
|||
st # to |
|||
sf # from |
|||
sn # n |
|||
6 # |
|||
lf # |
|||
- # |
|||
lt # |
|||
- # 6 - from - to |
|||
sl # |
|||
lp 0 =x # |
|||
lp 0 !=y # |
|||
lrx # loop |
|||
]sr |
|||
5lix # init(n) |
|||
lrx # run() |
|||
</pre> |
|||
=={{header|E}}== |
=={{header|E}}== |