Created
November 1, 2012 09:53
-
-
Save dheerajrav/3992798 to your computer and use it in GitHub Desktop.
Probability balls problem score calculator
This file contains 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 balls_score(n, q, a) | |
#n is the size for which the game is played | |
#q is the number of questions asked | |
#a is the number of attempts | |
if q<((n/2) + 1) | |
return 0 | |
end | |
k = n/10 | |
if k<2 | |
k = 2 | |
end | |
max = (k-1.0)*(n - k/2.0) | |
max = n*(k-1.0) - k*(k-1)/2.0 | |
score = (max - q)/max | |
ans = 100*score/(2**(a-1)) | |
if ans<1 | |
return 1 | |
else | |
return ans | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment