Towers of Hanoi: Difference between revisions
Content deleted Content added
No edit summary |
No edit summary |
||
Line 201: | Line 201: | ||
hanoi(ndisks=4) |
hanoi(ndisks=4) |
||
</pre> |
|||
==[[Ruby]]== |
|||
[[Category:Ruby]] |
|||
<pre> |
|||
def hanoi n,a='left',b='middle',c='right' |
|||
return if n==0 |
|||
hanoi (n-1),a,c,b |
|||
puts "Move from #{a} to #{b}" |
|||
hanoi (n-1),c,b,a |
|||
end |
|||
</pre> |
</pre> |
||