Created
January 11, 2016 06:18
-
-
Save kscottz/ecc0a03309e529713f59 to your computer and use it in GitHub Desktop.
This file contains 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
import itertools as it | |
def make_cards(n,m=[0,100,200,300,400]): | |
values = [n+mm for mm in m] | |
cards = [] | |
for card in it.permutations(values): | |
cards.append(list(card)) | |
return cards | |
def run_alg(cards,alg): | |
results = [] | |
for card in cards: | |
price = alg(card) | |
results.append({"deck":card,"price":price}) | |
return results | |
def calculate_avg(results): | |
prices = [p["price"] for p in results] | |
return sum(prices)/float(len(prices)) | |
def my_alg(cards): | |
last = cards[0] | |
for c in cards[1:]: | |
if c < last: | |
return c | |
else: | |
last = min([c,last]) | |
return cards[-1] | |
cards = make_cards(1000) | |
results = run_alg(cards,my_alg) | |
for r in results: | |
print r | |
print calculate_avg(results) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment