Grieve (grieve) wrote,
Grieve
grieve

Python Version

In regards to this, here is the python version:

def initialList(size):
   return [0 for x in range(size)]

def XinY_Go(x,y,index,slots):
   if (y - index) == 1:
      slots[index] = x
      print slots
      slots[index] = 0
      return
   for i in range(x+1):
      slots[index] = x-i
      XinY_Go(x-(x-i), y, index + 1, slots)

def XinY(x,y):
   return XinY_Go(x,y,0,initialList(y))

My next task is to remove the recursion. I have a fairly good idea of how to do it, but it will take me a few iterations to get it right.
Tags: math, progamming
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments