[Haskell-beginners] tower hanoi problem
Sumit Sahrawat, Maths & Computing, IIT (BHU)
sumit.sahrawat.apm13 at iitbhu.ac.in
Tue Feb 17 15:09:32 UTC 2015
Think of the function,
hanoi :: Integer -> Peg -> Peg -> Peg -> [Move]
As printing the following moves:
1. Move (n - 1) discs from peg1 to peg2 using peg3
2. Move 1 disc from peg1 to peg3 using peg2
3. Move (n - 1) discs from peg2 to peg3 using peg1
The main idea behind towers of hanoi is that you are constrained, and
cannot move many discs at once. But using an *intermediate peg*, you can
eventually move all discs to the target peg.
On 17 February 2015 at 17:53, Roelof Wobben <r.wobben at home.nl> wrote:
> Joel Neely schreef op 17-2-2015 om 13:05:
>
> Let's tweak your answers just a bit, calling the three pegs the
> "source", "goal", and "spare" pegs:
>
> On Tue, Feb 17, 2015 at 5:23 AM, Roelof Wobben <r.wobben at home.nl> wrote:
>
>> - Where do I move the bottom (largest disk) ?
>>
>> To the last peg, which do not contain any disk then
>> .
>>
>
> From the source peg to the goal peg, which will
> /must
> not contain any disks.
>
>
>>
>>
>>
>> - What must happen before I can move the bottom disk ?
>>
>> I have to move the disk which above that disk.
>>
>
> Move everything else from source to sparel peg.
>
>
>>
>> - What must happen after I move the bottom disk ?
>>
>> All the other disk must be placed above that disk.
>>
>
> Move everything else from spare to goal.
>
>
> So more questions/hints:
>
> 1. How do you fill in the blanks?
> 2. How do you put the three statements in order?
> 3. How many disks does each statement talk about?
>
>
> -jn-
>
>
>
> 1. I did already.
> 2. First move everything except the bottom one to the spare peg.
> Move the bottom one to the goal peg.
> Move everything else from the spare peg to the goal peg.
>
> 3. Only 2
>
> Roelof
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
--
Regards
Sumit Sahrawat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150217/3b72bdfc/attachment.html>
More information about the Beginners
mailing list