Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

(Golf) Towers of Hanoi

by z0d (Hermit)
on Jul 29, 2001 at 00:49 UTC ( #100601=perlmeditation: print w/replies, xml ) Need Help??

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 -->

Replies are listed 'Best First'.
Re: (Golf) Towers of Hanoi
by Anonymous Monk on Jun 23, 2002 at 23:05 UTC
    perl -we '$\.=$_.$/.$\for 0..~-pop;print' 3
      You don't just eviscerate a Ton Hospel solution, and walk nonchalantly away with a smug grin under your masked visage. Identify yourself, and the planet and star-system from which you hale.
                     s aamecha.s a..a\u$&owag.print
        I'm allowed to eviscerate my own solutions ! Though this time Jukka Suomela helped a lot.
Re: (Golf) Towers of Hanoi
by lemming (Priest) on Jul 29, 2001 at 07:19 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://100601]
Front-paged by ariels
[erix]: comic relief: how to start a riot and a fortune at the same time
[beech]: :) thats too generous to jdporter, don't start none won't be none -- there is about two decades (rounding up) worth of "ineffective" node titles -- leave the pope alone :p
[erix]: infallibility breeds inquisition

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2017-01-17 23:54 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (159 votes). Check out past polls.