title: Need help understanding recursion for python
body: <p>I am new to recursion and want to know what is the logic to the following code. </p>
  
  <p>The question is the powerSums question on hackerrank: <a href="https://www.hackerrank.com/challenges/the-power-sum/problem?isFullScreen=true" rel="nofollow noreferrer">https://www.hackerrank.com/challenges/the-power-sum/problem?isFullScreen=true</a></p>
  
  <pre><code>def powerSum(X, N, current = 1):
      pw = pow(current, N)
      if pw &gt; X:
          return 0
      elif pw == X:
          return 1
      else:
          return powerSum(X, N, current+1) + powerSum(X-pw, N, current+1)
  </code></pre>
  
  <p>Also, I had been trying to convert the answer to a nested list or tuple of the set of values, but cannot seem to figure it out. How can this be done?</p>
  
  <p>Eg, for a case where X=5 and N=2, the solution I want to yield is:
  [(10), (6,8), (1,3,4,5,7)] instead of 3, which the above code is yielding.</p>