Skip to content

Instantly share code, notes, and snippets.

@kscottz
Created January 11, 2016 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kscottz/ecc0a03309e529713f59 to your computer and use it in GitHub Desktop.
Save kscottz/ecc0a03309e529713f59 to your computer and use it in GitHub Desktop.
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