2019-수학-가형-홀수-4¶
문제¶
풀이¶
from random import randint
from sympy import Rational
def random_subset(s):
out = set()
for el in s:
# random coin flip
if randint(0, 1) == 0:
out.add(el)
return out
def Prob(S):
return Rational(len(S), len(U))
def complement(S):
# difference between a global universal set U and the given set a
return U - S
def intersection(a,b):
return set(a) & set(b)
U= set(range(1,7))
A={1,2}
Ac=complement(A)
Bnotfound = True;
while Bnotfound:
B = random_subset(U)
Bc = complement(B)
if Prob(intersection(A, Bc)) == 0 and Prob(intersection(Ac, B))==Rational(1,6) :
Bnotfound = False;
print([B, Prob(B)])
break
[{1, 2, 6}, 1/2]