Created
March 1, 2014 23:57
-
-
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…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ruby version : https://gist.github.com/prat0318/9299888