I was told to solve the mathematical probability of some entrance exam problem, and I didn't want to think about it, so I left it to python for a moment.
There are 20 cards with integers from 1 to 20 written on them. Find the probability that the sum of the numbers on the 17 cards taken out at the same time will be a multiple of 3.
If you try to solve it by hand, think about the combination, and it's okay if 3 cards become 3 swords ...
I wrote it in python. It's so short that it doesn't matter what the processing speed is, so I use for statements all the time.
import numpy as np
import random
calculuse = []
result = []
for i in range(1, 20):
for k in range (i+1, 21):
for l in range(k+1, 21):
a = i+k+l
print('(i, k, l) =',i,(','),k,(','),l,('sum='),i+k+l)
array = a
calculuse.append(array)
if a%3 == 0:
print('true')
else:
print('false')
arr = [a, a%3==0]
if a%3 ==0:
result.append(arr)
print(len(result))
print(len(calculuse))
That's it!
(i, k, l) = 1 , 2 , 3 sum= 6
true
(i, k, l) = 1 , 2 , 4 sum= 7
false
(i, k, l) = 1 , 2 , 5 sum= 8
false
(i, k, l) = 1 , 2 , 6 sum= 9
true
(i, k, l) = 1 , 2 , 7 sum= 10
false
(i, k, l) = 1 , 2 , 8 sum= 11
false
(i, k, l) = 1 , 2 , 9 sum= 12
true
(i, k, l) = 1 , 2 , 10 sum= 13
false
(i, k, l) = 1 , 2 , 11 sum= 14
false
(i, k, l) = 1 , 2 , 12 sum= 15
true
(i, k, l) = 1 , 2 , 13 sum= 16
false
(i, k, l) = 1 , 2 , 14 sum= 17
false
(i, k, l) = 1 , 2 , 15 sum= 18
true
(i, k, l) = 1 , 2 , 16 sum= 19
false
(i, k, l) = 1 , 2 , 17 sum= 20
false
(i, k, l) = 1 , 2 , 18 sum= 21
:
:
:
:
384
1140
So the answer is 384/1140 Will be! I was told that I would like to know my thoughts when I gave it to a friend.
Recommended Posts