title: Explain this Python program
body: <pre><code>def hanoi(n, A, C, B):
      def print_move(A, C):
          print(A, '--&gt;', C)
  
      if n == 1:
          print_move(A, C)
  
      else:
          hanoi(n-1, A, B, C)
          hanoi(1, A, C, B)
          hanoi(n-1, B, C, A)
  </code></pre>
  
  <p>This is a program that solves the towers of hanoi problem, however I don't understand it at all.</p>
  
  <ol>
  <li><p>When will the program end?</p></li>
  <li><p>When n-1 gets to 1 shouldn't it get stuck in infinite loop because of the condition?</p></li>
  <li><p>The program will work as intended until hanoi(1, A, C, B), because of the condition it will print A --> B, but shouldn't it print A --> C?</p></li>
  <li><p>Can any of the recursive functions affect others (hanoi2 sets n to 1, but will hanoi3 also use 1 or n-1?) and which lines will execute in order?</p></li>
  </ol>