[Haskell-beginners] tower of hanoi problem

YCH dontdieych at gmail.com
Sat Feb 14 13:16:52 UTC 2015


On Sat, Feb 14, 2015 at 4:39 AM, Roelof Wobben <r.wobben at home.nl> wrote:
> Hello,
>
> After a short break I try to make the next assignment of the CIS 194 course.
> I do self-study.
>
> Lets say we have 1 disk with 2 pegs then we have this :
>
>
> type Peg = String.
> type Move = (Peg, Peg)
> Hanoi :: Integer -> Peg -> Peg -> [Move]
>
> So I can do this Hanoi 2 a b

Should it be,

hanoi :: Integer -> Peg -> Peg -> Peg -> [Move]

?

So,

hanoi n a b c
hanoi 2 "a" "b" "c"

- You have n disks at 'a' peg in right order(bigger is on bottom).
- n should be >= 2.
- You have to move all disk from 'a' to 'b'.
- You can use 'c' as your temporary place.

I've done this as,

- write 'hanoi 2 "a" "b" "c"
- write 'hanoi 3 "a" "b" "c"
- write 'hanoi 4 "a" "b" "c"
- find some common pattern

>I do not see how I can tell that the disk can move from a to b

Output of hanoi is 'move plan'. It does not actually do somthing.

[ ("a", "b")
, ("a", "c")
]

means,

- move disk on top of "a" peg to "b"
- move disk on top of "b" peg to "c"


More information about the Beginners mailing list