Skip to content

Instantly share code, notes, and snippets.

@dheerajrav
Created November 1, 2012 09:53
Show Gist options
  • Save dheerajrav/3992798 to your computer and use it in GitHub Desktop.
Save dheerajrav/3992798 to your computer and use it in GitHub Desktop.
Probability balls problem score calculator
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