[Haskell-beginners] tower hanoi problem
Joel Neely
joel.neely at gmail.com
Tue Feb 17 16:13:04 UTC 2015
Regarding your last answer...
3. Only 2
...let me suggest a different perspective. If we begin with n disks, then:
First move everything except the bottom one to the spare peg.
"everything except the bottom one" refers to
(
n
- 1)
disks
Move the bottom one to the goal peg.
"the bottom one" refers to 1 disk
Move everything else from the spare peg to the goal peg.
"everything else" refers to
(
n
- 1)
disks
So that moves the thought process toward the "fancier recursion pattern"
per Doug McIlroy's excellent summary.
On Tue, Feb 17, 2015 at 6:23 AM, 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
>
>
--
Beauty of style and harmony and grace and good rhythm depend on simplicity.
- Plato
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150217/4ff991bc/attachment-0001.html>
More information about the Beginners
mailing list