Created
March 2, 2014 00:29
-
-
Save prat0318/9299888 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
def func(x, p, a, g) | |
return 1 if [x,p,a,g].all?(&:zero?) | |
return 0 if [p,a,g].any? {|i| i<0} || x == 0 || p+a+g<x | |
(0..7).map{|i| ("%03b" % i)}.inject(0){|cnt, pos| cnt + func(x-1, p - pos[0].to_i, a - pos[1].to_i, g - pos[2].to_i)} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment