[Esame 20 Luglio 2021] Esercizio 1 #259
Replies: 3 comments
-
Sia |
Beta Was this translation helpful? Give feedback.
-
La bonta' dei risultati e' stata provata mediante la seguente simulazione import random
def test(iterations, *tests):
print(", ".join(t.__name__ + ": " + str(sum(t() for _ in range(iterations)) / iterations) for t in tests))
class Card:
__slot__ = (
"number",
"seed"
)
seeds = [*range(4)]
def __init__(self, number, seed):
self.number = number
self.seed = seed
@property
def n(self): return self.number
cards = [Card(n, s) for s in Card.seeds for n in range(1, 11)]
# a)
def a1():
random.shuffle(cards)
return cards[0].n == 7
def a2():
random.shuffle(cards)
return {cards[0].n, cards[1].n} == {3, 4}
# b
def b():
random.shuffle(cards)
return (cards[0].n, {cards[1].n, cards[2].n}) == (7, {3, 4})
# c)
def c():
random.shuffle(cards)
while cards[0].n < 8:
random.shuffle(cards)
return cards[1].n + cards[2].n == 7
# d)
def d():
random.shuffle(cards)
while cards[0].n + cards[1].n != 7:
random.shuffle(cards)
return cards[2].n >= 8
test(100000, a1, a2, b, c, d) |
Beta Was this translation helpful? Give feedback.
-
(1) L'estrazione di (2) (3) Il fatto che (4) Utilizzo la probabilità condizionata e Bayes: A questo punto sappiamo che Se Quindi svolgendo i calcoli si ottiene:
|
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
All reactions