Created
June 19, 2014 11:47
-
-
Save akleemans/17fc72c124973ec9d6a2 to your computer and use it in GitHub Desktop.
Simulation, how many Panini packages have to be bought to get a full album.
This file contains hidden or 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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
''' | |
Simulates how many packages of Panini pictures have to be bought to get a certain amount of pictures. | |
@author: Adrianus Kleemans | |
@date: 19.06.2013 | |
''' | |
import random | |
TOTAL_PICS = 660 | |
PICS_PER_PACKAGE = 5 | |
SIMULATIONS_COUNT = 100 | |
def buy_package(): | |
package = [] | |
while len(package) < PICS_PER_PACKAGE: | |
new_pic = random.randint(1, TOTAL_PICS) | |
if new_pic not in package: package.append(new_pic) | |
return package | |
for wanted_pics in range(1, TOTAL_PICS+1): | |
counts = [] | |
for _ in range(SIMULATIONS_COUNT): | |
rounds = 0 | |
pictures = [] | |
# buy a package of 5 pics | |
while len(pictures) < wanted_pics: | |
rounds += 1 | |
for pic in buy_package(): | |
if pic not in pictures: | |
pictures.append(pic) | |
counts.append(rounds) | |
print wanted_pics, ";", sum(counts)/len(counts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment