Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- def simulate(n):
- simulations = n
- birthdays = []
- attempts = 0
- while simulations > 0:
- for _ in range(n):
- day = randint(0, 365)
- if day in birthdays:
- birthdays = []
- simulations -= 1
- else:
- birthdays.append(day)
- attempts += 1
- return attempts / n
- print("Det behövs i medelsnitt", simulate(100),
- "elever innan två har samma födelsedag")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement