title: Recursive function (bracket sequence)
body: <p>This not my decision but I want to know how it work's. Put <code>print</code> into function. Task: Find all correct bracket sequence where length is <code>2 ⋅ n</code>. Only round brackets.</p>
  
  <pre><code>def foo(search, left, right, pairs):
      if left == pairs and right == pairs:
          print(search)
      else:
          print(left, right, 'else',)
          if left &lt; pairs:
              print(left, right,'left')
              foo(search + '(', left + 1, right, pairs)
          if right &lt; left:
              print(left, right, 'right')
              foo(search + ')', left, right + 1, pairs)
  
  foo('', 0, 0, 3)
  </code></pre>
  
  <p>Until the first correct sequence generation all clear. But next there are some questions. There are <code>prints</code> from first to second correct generation:</p>
  
  <pre><code>((()))
  2 0 right
  2 1 else
  2 1 left
  3 1 else
  3 1 right
  3 2 else
  3 2 right
  (()())
  </code></pre>
  
  <p>Why in first <code>print</code> after first correct sequence <code>left, right = 2, 0</code>?</p>