Towers of Hanoi: Difference between revisions
→{{header|J}}: Add lang tags, improve readability of explicit defintion.
(→{{header|J}}: Add lang tags, improve readability of explicit defintion.) |
|||
Line 432:
=={{header|J}}==
<lang j>
H =: i.@(,&2) ` (({&0 2 1,0 2,{&1 0 2)@$:@<:) @. *▼
H1=: monad define
if. *y do.
else.
i.0 2
end.
)
</lang>
<tt>H</tt> employs anonymous recursion; <tt>H1</tt> is an "explicit" statement of the same computation. For example:
<lang j>
</lang>
The result is a 2-column table; a row <tt>i,j</tt> is interpreted as: move a disk (the top disk) from peg <tt>i</tt> to peg<tt> j</tt> .
|