title: recursive function affecting variable
body: <p>I have a recursive function to count the number of way 8 queens can fit on an 8x8 chess board without intersecting each other (for a class). It works well and gives the correct permutations, the interesting thing happens when I have the program try to count the # of answers -it constantly returns my counter to zero. When I manually count the permutations it's 92 (which is correct).</p>
  
  <pre><code>def can_be_extended_to_solution(perm):
      i = len(perm) - 1
      for j in range(i):
          if i - j == abs(perm[i] - perm[j]):
              return False
      return True
  
  def extend(perm,count, n):
      if len(perm)==n:
          count=count+1
          print "cycle counter= ",count
          print(perm)
  
      for k in range(n):
          if k not in perm:
              perm.append(k)
              if can_be_extended_to_solution(perm): # if it works
                  extend(perm, count, n)
              perm.pop()        
  
  extend(perm = [], count=0, n = 8)
  </code></pre>