Skip to content

Instantly share code, notes, and snippets.

@artjomb artjomb/birthday.groovy Secret
Last active Jun 12, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.