Learn Recursion by Solving the Tower of Hanoi Puzzle - Step 3

Tell us what’s happening:

Hello, I was able to obtain the correct answer for this question; however, I was confused as to why a negative number was used instead of 2 being the difference between 3 to 1 or why a 1 could not be used?

I know that:

  • x = 3 bcuz that is our starting point
  • y = 0 bcuz its a # that is not included
    but h ? the only reason I would assume its a negative is becuase we’re counting backwards on our list is that correct?

Can someone please explain this to me I would be grateful! Thank you!

Your code so far


# User Editable Region

rods = {
    'A': [],
    'B': [],
    'C': []
}
rods['A']=range(x, y, h)

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

Learn Recursion by Solving the Tower of Hanoi Puzzle - Step 3

Welcome to the forum @Nuir

h is the difference between a number and the next one in the sequence

So the difference between a and the next one, b, is b - a.

For example, starting at 3, the next in the sequence is 2.
So 2 - 3 equals -1

If the difference is positive, the sequence increments.
If the difference is negative, the sequence decrements.

Happy coding

2 Likes

Oh I see thank you for the explanation!

Also is there extra resource to learn about these things/ If you know of any?

1 Like

there is a lot of articles on freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More, you could also find interesting the official Python documentation, or do a google search for whatever you have doubts about

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.