Towers of Hanoi: Difference between revisions

Content added Content deleted
(→‎{{header|Groovy}}: new solution)
m (fix bare lang tags)
Line 555: Line 555:
] when ;</lang>
] when ;</lang>
In the REPL:
In the REPL:
<lang>( scratchpad ) 3 1 3 2 hanoi
<pre>( scratchpad ) 3 1 3 2 hanoi
1->3
1->3
1->2
1->2
Line 562: Line 562:
2->1
2->1
2->3
2->3
1->3</lang>
1->3</pre>


=={{header|Forth}}==
=={{header|Forth}}==
Line 867: Line 867:
The usage here is the same:
The usage here is the same:


<lang> H1 2
<pre> H1 2
0 1
0 1
0 2
0 2
1 2</lang>
1 2</pre>


'''Alternative solution'''<br>
'''Alternative solution'''<br>
Line 1,108: Line 1,108:
hanoi(4, "1", "2", "3")</lang>
hanoi(4, "1", "2", "3")</lang>
Output:
Output:
<lang>Move disk 1 from 1 to 3
<pre>Move disk 1 from 1 to 3
Move disk 2 from 1 to 2
Move disk 2 from 1 to 2
Move disk 1 from 3 to 2
Move disk 1 from 3 to 2
Line 1,122: Line 1,122:
Move disk 1 from 1 to 3
Move disk 1 from 1 to 3
Move disk 2 from 1 to 2
Move disk 2 from 1 to 2
Move disk 1 from 3 to 2</lang>
Move disk 1 from 3 to 2</pre>
=={{header|NewLISP}}==
=={{header|NewLISP}}==
<lang>
<lang lisp>
(define (move n from to via)
(define (move n from to via)
(if (> n 0)
(if (> n 0)
Line 1,132: Line 1,132:




(move 4 1 2 3)
(move 4 1 2 3)</lang>
</lang>


=={{header|Objective-C}}==
=={{header|Objective-C}}==
Line 1,675: Line 1,674:
and somewhat obtuse features of the REXX language, the smallest of which
and somewhat obtuse features of the REXX language, the smallest of which
is support for ASCII and EBCDIC "graphic" characters.
is support for ASCII and EBCDIC "graphic" characters.
<lang>
<lang rexx>
/*REXX program shows pictorial moves to solve Tower of Hanoi (3 disks). */
/*REXX program shows pictorial moves to solve Tower of Hanoi (3 disks). */