Skip to content

Instantly share code, notes, and snippets.

@jubishop
Created April 26, 2016 19:50
Show Gist options
  • Save jubishop/81b25a9ed286e7bf21fab005d5df3048 to your computer and use it in GitHub Desktop.
Save jubishop/81b25a9ed286e7bf21fab005d5df3048 to your computer and use it in GitHub Desktop.
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