Skip to content

Instantly share code, notes, and snippets.

@akleemans akleemans/panini.py
Created Jun 19, 2014

Embed
What would you like to do?
Simulation, how many Panini packages have to be bought to get a full album.
#!/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
You can’t perform that action at this time.