Skip to content

Instantly share code, notes, and snippets.

@prat0318
Created March 1, 2014 23:57
Show Gist options
  • Save prat0318/9299574 to your computer and use it in GitHub Desktop.
Save prat0318/9299574 to your computer and use it in GitHub Desktop.
There are three singers Prateek, Akanksha and gurbinder. They are doing a concert to celebrate my awesomeness. I have asked them to sing X distinct number of songs. Though each one of them want to sing all X songs, but due to their limits, each one has to sing P, A and G songs. All songs can be sung by either 1, 2 or 3 of them. Each of the X son…
f = lambda i,j: int("{0:b}".format(i+1).zfill(3)[j])
def func(x, p, a, g):
if(p == 0 and a == 0 and g == 0 and x == 0): return 1
if(p < 0 or a < 0 or g < 0 or p+a+g < x or x==0): return 0
l = lambda count, pos: count + func(x-1, p-f(pos,0), a - f(pos,1), g - f(pos,2))
return reduce(l, range(7), 0)
print func(3,1,1,3) #9
print func(50,10,10,10) #0
@prat0318
Copy link
Author

prat0318 commented Mar 2, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment