Created
April 26, 2016 19:50
-
-
Save jubishop/81b25a9ed286e7bf21fab005d5df3048 to your computer and use it in GitHub Desktop.
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 expn(a, b) | |
a = a.to_r | |
b = b.to_i | |
d = 1.to_r | |
while(b > 0) | |
d *= a if (b % 2 == 1) | |
b /= 2 | |
a *= a if (b > 0) | |
d = d.round(100) | |
a = a.round(100) | |
end | |
d.to_f | |
end | |
def p(n, d) | |
d = d.to_r | |
n = n.to_r | |
1 - expn((d - 1)/d, n*(n-1)/2) | |
end | |
puts p(ARGV.first.to_i, 2**64) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment