Tell us what’s happening:
I’ve read different posts, I saw different solutions but I don’t UNDERSTAND it.
This is the last certification Project that I need and I don’t get it.
I know how the tower of hanoi works, i’ve seen a pattern in the expected outcome
e. g.: odd numbers are being pushed to the left tower and even numbers to the middle
BUT I DON’T KNOW HOW TO DO IT
Algorithms are my weakpoint ever since JS. I need some form of push to the right direction, so if anyone has a tip, please do tell me, thank you!
Your code so far
def hanoi_solver(disks):
left = list(range(disks, 0, -1))
mid = []
right = []
sol = [] + left
num_of_moves = 2 ** disks - 1
count = 0
result = ""
while right != sol and count < num_of_moves:
count += 1
print(count, num_of_moves)
return result
hanoi_solver(3)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:154.0) Gecko/20100101 Firefox/154.0
Challenge Information:
Implement the Tower of Hanoi Algorithm - Implement the Tower of Hanoi Algorithm
GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-tower-of-hanoi/68773ee26f332a80bc0295db.md at main · freeCodeCamp/freeCodeCamp · GitHub
PS: I didn’t wanna include the code just know but yeah. The loop is there to automatically stop after 2^n - 1 moves
Hey, don’t worry, I’ve been there too, I was stuck on it for like 2 months and still now I really don’t get how I did it.
Algorithms are incredibly complicated and I struggle every time I deal with it.
So what I’ve done is an approach by recursion (btw if you want to do the same I think that it is easier with the dynamic programming things, however it is only my personal experience and you should stay with what you like the most), and it was super-duper confusing (and is still now).
What I understand is that in all position, the disk has three places to go: the starter (where he begins), the helper and the end (where we want to reach). For example, if you have one disk, the starter is left, the helper is midand the end is right. Then, when you have more than that, you change the poles that are used as starter, helper and end.
That was my personal thinking, but I’m trying to understand yours. What exactly is the role of sol?
Anyways hope this post helped you; I get it if you’re confused even more just forget what I said.
This is in my opinion the hardest thing in the curriculum, so best advice is don’t give up! It can be hard, but you’ll do it! Have fun coding!
Recursion was my breaking point in JS also xD
I’ve had a couple of “why does this work” moments and never questioned it.
Sol stands for “solution” and is there to check if the right pole is the same as sol, aka if I succeeded in making the algorithm.
The reason why I also put the count < num_of_moves limit in my while loop, is because if I mess up, I don’t want the code to run infinetly and slow down my website.
I don’t understand Recursion much, even now. I had to skip some algorithms in JS and the only Lab I’ve skipped so far, is the “Quicksort Algorithm” in Python. So I don’t know if Recursion will help me much in this one
I’ve read a solution online and now kinda get it?
Never in a million years would I’ve gotten that solution, I already know that I will skip: DFS, BFS and N-Queens Algorithm, since I wasn’t able to get it in JavaScript and will definitely not get it now.
Thanks for your help!
Uhh, if you’re really struggling with recursion, I don’t think skipping all the exercises is the best way to progress. It’s a key skill to master, so I wouldn’t recommend giving up on it, even if it has to take 6 months or a year. If your goal is to know how to fully code with Python or JS, but you skip a part of it, you’re not fulfilling your objective, isn’t it ?
As I said earlier, some dynamic programming concepts actually made recursion easier to understand for me (or finding some alternatives), even though it’s not the primary goal of the lesson (check out the page on the curriculum)
I admire your endurance, but I simply don’t have that.
I tried understanding recursion over and over and over and sometimes, I just can’t understand things and that’s fine.
I understand the core of recursion, what a call stack is, etc. but I don’t want to torture myself if I don’t understand it.
I WILL READ the theories, DO the workshops and TRY the labs, but if I don’t understand it, I will stop and I don’t see anything wrong with that
Yeah I understand… Well, hope this helped you, have fun coding 
you too and thank you so much! 