What you did recursively is ...
.. which is not what you want. Keep thinking, you will get it.
Some things to consider:
By keeping track, I mean keep track of which peg is filled first.
Hope this helps.

On 19 February 2015 at 19:20, Roelof Wobben <r.wobben@home.nl> wrote:
Hello,

I try now to make the optional exercise hanoi with 4 pegs,

So I did on paper this :

start               temp1               temp2                  end

3
2
1

first move  :  start -> temp2

start               temp1           temp2 end
2                                              3
1

second move : start -> temp1

start                  temp1       temp2                      end
1                        2                  3

now I tried to make this piece in code

So I did :

hanoi4 1 start _  _ end = "move 1 disk from " ++ [start] ++ " to " ++ [end] ++ ".\n"
hanoi4 n start temp1 temp2 end = hanoi4 (n-1) start end temp1 temp2 ++ hanoi4 1 start end temp1 temp2 ++ hanoi4 (n-1) start  temp1 end temp2

because on the first step   start must be  start and  end must be temp1
and on the second step start must be start and end must be temp2

but when I run in I see this output :

move 1 disk from a to b.
move 1 disk from a to b.
move 1 disk from a to b.
move 1 disk from a to c.
move 1 disk from a to d.
move 1 disk from a to d.
move 1 disk from a to d.

Can anyone explain or let me see where my thinking took the wrong turn ?

Roelof



_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



--
Regards

Sumit Sahrawat