I found this one pretty tough, because there are two big steps:
- Design the algorithm
- implement the algorithm
Can you describe in English or pseudo code the algorithm that you are trying to implement? Do this planning and research first, before you start coding.
I would suggest doing a lot of outside research about the algorithm itself until you have an understanding of it.
Here’s how yours is working:
[3, 2, 1] [] []
[3, 2] [] [1]
[3] [2] [1]
[3] [2, 1] []
[] [2, 1] [3]
[1] [2] [3]
[] [2] [3, 1]
Your algorithm does well here until [] [2] [3, 1] it should have moved 2 instead [1] [] [3, 2]
[2, 1] [] []
[2] [] [1]
[] [2] [1]
[] [2, 1] []
Here as well, it should do this instead:
[2, 1] [] []
[2] [1] []
[] [1] [2]
[] [] [2,1]
Here it should have ended at the second step, right?
[1] [] []
[] [] [1] #end here
[] [1] []
Make sure your algorithm works for these smaller, simpler values first.
There’s no situation where your program should return 'Incorrect solution'
Again, I suggest a lot of research to understand the problem better. This video really helped me to understand the algorithm
https://www.youtube.com/watch?v=rf6uf3jNjbo
Here’s an explanation with pseudo code: https://expertbeacon.com/how-to-solve-the-tower-of-hanoi-problem-an-illustrated-algorithm-guide/
This also has good information about the algorithm to follow https://www.youtube.com/watch?v=fESwgKNITGE
This one is interesting but I’m not sure how useful it is https://www.youtube.com/watch?v=PGuRmqpr6Oo
Some of these links do have code implementations but they are a bit different than what is required for this challenge.