Skip to content

Instantly share code, notes, and snippets.

@mpawliuk
Created September 5, 2017 05:42
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 mpawliuk/46404324d09c025ea3aa3a03ac7848b6 to your computer and use it in GitHub Desktop.
Save mpawliuk/46404324d09c025ea3aa3a03ac7848b6 to your computer and use it in GitHub Desktop.
#Packs = ((points - rounds) - (rounds - 3))
#Take one point off for a perfect record.
def points(record):
"""Give the number of points a certain record is worth."""
w, l, d = record[:3]
return 3 * w + 1 * d
def packs_awarded(record, rounds):
"""Calculate the number of packs to give someone with a given record."""
total = points(record) - 2 * rounds + 3
return total - 1 if points(record) == 3 * rounds else max(0, total)
def nice_show(record):
"""Display a record in w-l-d format."""
w, l, d = record[:3]
return str(w) + '-' + str(l) + '-' + str(d)
def show_pack_distribution(rounds):
"""Show how many packs each possible record gets. No ties or drops."""
possible_records = [(i, rounds - i, 0) for i in range(rounds + 1)]
for records in possible_records:
print '*', nice_show(records), 'gets', packs_awarded(records, rounds), 'packs'
return None
def compute_records(rounds, records):
"""Give how many people of each record there will be, assuming 2^rounds many players.
Doesn't work for 5+ rounds because it doesn't take into account pair-up/pair-downs.
"""
if rounds == 0:
return records
records.append(0)
for i in range(1, len(records)):
#print records
winners = records[-i-1]
#print winners
records[-i] += winners / 2
records[-i-1] -= winners / 2
#print rounds-1, records
return compute_records(rounds-1, records)
def total_packs_given_out(rounds):
"""Compute how many total packs are given out."""
records = [(i, rounds - i, 0) for i in range(rounds + 1)]
total_packs = 0
for i in range(rounds + 1):
total_packs += packs_awarded(records[i], rounds) * compute_records(rounds, [rounds ** 2])[i]
print '*', nice_show(records[i]), 'gets', packs_awarded(records[i], rounds), 'packs', compute_records(rounds, [rounds ** 2])[i], 'total people'
return total_packs
r = 4
#print compute_records(r, [2 ** r])
print total_packs_given_out(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment