I searched PerlMonks
for towers of hanoi, but couldn't find anything. It is strange because there isn't any good reason not to golf this game. Since I'm not good at golf, I can provide only Ton Hospel's two solutions to the problem.
perl -wle 'print log(~$_&($_+1))/log 2 for 0..2**pop()-2' 3
perl -wle '$n=-1+2**pop;print log($n--&~$n)/log 2while$n' 3
It tells which disk to move for 3 disks.
Replace the 3 at the end for the other numbers up to 32.
There's always only one possibility since top disk goes where it has not been yet. Unfortunatelly it works only under 32.
<-- z0d -->
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||