Last active
March 31, 2020 04:11
-
-
Save laalaguer/924cef55ed17ad49a0d62ef09b130b0f to your computer and use it in GitHub Desktop.
# In 100 numbers, # Have x numbers, that are <= y, # The possibly.
This file contains 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
# Python3 | |
# In 100 numbers, | |
# Exactly has (n) numbers, that are <= value | |
# The possibility. | |
def f(n, value): | |
a = 1 - value/100 | |
b = value/100 | |
# Numbers that are > 8 | |
part_1 = a ** (100 - n) # (0.92) ^ (100-n) | |
# Numbers that are <=8 | |
part_2 = b ** n # (0.08) ^ n | |
# Pick up (n) slots, to accommodate those (n) numbers. | |
# part_3 = C(100, n) = (100 !) / ((100 - n)! * n!) = (1 * 2 * ... * 100) / ((1 * 2 * ... *(100-n) * (1 * 2 * ... n)) | |
part_3 = 1 | |
for i in range(1, 100+1): | |
part_3 = part_3 * i | |
for i in range(1, (100-n) + 1): | |
part_3 = part_3 / i | |
for i in range(1, n + 1): | |
part_3 = part_3 / i | |
return part_1 * part_2 * part_3 | |
# In 100 numbers, | |
# Have x numbers, that are <= y, | |
# The possibly. | |
def test(x, y): | |
total = 0 | |
for i in range(x, 100+1): # [x,...100] | |
total += f(i, y) | |
print('at least have '+ str(x) + ' and more numbers, that are <=' + str(y), ',', str(round(total * 100)) + '%' ) | |
for i in range(8, 20 + 1): | |
test(5, i) | |
test(6, i) | |
test(7, i) | |
test(8, i) | |
test(9, i) | |
test(10, i) | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
at least have 5 and more numbers, that are <=8 , 91%
at least have 6 and more numbers, that are <=8 , 82%
at least have 7 and more numbers, that are <=8 , 70%
at least have 8 and more numbers, that are <=8 , 55%
at least have 9 and more numbers, that are <=8 , 41%
at least have 10 and more numbers, that are <=8 , 28%
at least have 5 and more numbers, that are <=9 , 95%
at least have 6 and more numbers, that are <=9 , 90%
at least have 7 and more numbers, that are <=9 , 81%
at least have 8 and more numbers, that are <=9 , 69%
at least have 9 and more numbers, that are <=9 , 55%
at least have 10 and more numbers, that are <=9 , 41%
at least have 5 and more numbers, that are <=10 , 98%
at least have 6 and more numbers, that are <=10 , 94%
at least have 7 and more numbers, that are <=10 , 88%
at least have 8 and more numbers, that are <=10 , 79%
at least have 9 and more numbers, that are <=10 , 68%
at least have 10 and more numbers, that are <=10 , 55%
at least have 5 and more numbers, that are <=11 , 99%
at least have 6 and more numbers, that are <=11 , 97%
at least have 7 and more numbers, that are <=11 , 93%
at least have 8 and more numbers, that are <=11 , 87%
at least have 9 and more numbers, that are <=11 , 78%
at least have 10 and more numbers, that are <=11 , 67%
at least have 5 and more numbers, that are <=12 , 99%
at least have 6 and more numbers, that are <=12 , 98%
at least have 7 and more numbers, that are <=12 , 96%
at least have 8 and more numbers, that are <=12 , 92%
at least have 9 and more numbers, that are <=12 , 86%
at least have 10 and more numbers, that are <=12 , 77%
at least have 5 and more numbers, that are <=13 , 100%
at least have 6 and more numbers, that are <=13 , 99%
at least have 7 and more numbers, that are <=13 , 98%
at least have 8 and more numbers, that are <=13 , 96%
at least have 9 and more numbers, that are <=13 , 92%
at least have 10 and more numbers, that are <=13 , 85%
at least have 5 and more numbers, that are <=14 , 100%
at least have 6 and more numbers, that are <=14 , 100%
at least have 7 and more numbers, that are <=14 , 99%
at least have 8 and more numbers, that are <=14 , 98%
at least have 9 and more numbers, that are <=14 , 95%
at least have 10 and more numbers, that are <=14 , 91%
at least have 5 and more numbers, that are <=15 , 100%
at least have 6 and more numbers, that are <=15 , 100%
at least have 7 and more numbers, that are <=15 , 100%
at least have 8 and more numbers, that are <=15 , 99%
at least have 9 and more numbers, that are <=15 , 97%
at least have 10 and more numbers, that are <=15 , 94%
at least have 5 and more numbers, that are <=16 , 100%
at least have 6 and more numbers, that are <=16 , 100%
at least have 7 and more numbers, that are <=16 , 100%
at least have 8 and more numbers, that are <=16 , 99%
at least have 9 and more numbers, that are <=16 , 99%
at least have 10 and more numbers, that are <=16 , 97%
at least have 5 and more numbers, that are <=17 , 100%
at least have 6 and more numbers, that are <=17 , 100%
at least have 7 and more numbers, that are <=17 , 100%
at least have 8 and more numbers, that are <=17 , 100%
at least have 9 and more numbers, that are <=17 , 99%
at least have 10 and more numbers, that are <=17 , 98%
at least have 5 and more numbers, that are <=18 , 100%
at least have 6 and more numbers, that are <=18 , 100%
at least have 7 and more numbers, that are <=18 , 100%
at least have 8 and more numbers, that are <=18 , 100%
at least have 9 and more numbers, that are <=18 , 100%
at least have 10 and more numbers, that are <=18 , 99%
at least have 5 and more numbers, that are <=19 , 100%
at least have 6 and more numbers, that are <=19 , 100%
at least have 7 and more numbers, that are <=19 , 100%
at least have 8 and more numbers, that are <=19 , 100%
at least have 9 and more numbers, that are <=19 , 100%
at least have 10 and more numbers, that are <=19 , 100%
at least have 5 and more numbers, that are <=20 , 100%
at least have 6 and more numbers, that are <=20 , 100%
at least have 7 and more numbers, that are <=20 , 100%
at least have 8 and more numbers, that are <=20 , 100%
at least have 9 and more numbers, that are <=20 , 100%
at least have 10 and more numbers, that are <=20 , 100%