Skip to content

Instantly share code, notes, and snippets.

@artjomb
Last active June 12, 2016 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artjomb/9320b8c91e30b78e3706408e023d61a1 to your computer and use it in GitHub Desktop.
Save artjomb/9320b8c91e30b78e3706408e023d61a1 to your computer and use it in GitHub Desktop.
calculating the birthday probability for 100000 in 2^170
import java.math.*;
BigDecimal r = new BigDecimal(2);
r = r.pow(160);
MathContext c = new MathContext(1000);
BigDecimal result = new BigDecimal(1);
for(int i = 0; i < 100000; i++) {
result = result.multiply(r.subtract(new BigDecimal(i)).divide(r)).round(c);
}
println BigDecimal.ONE.subtract(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment