Skip to content

Instantly share code, notes, and snippets.

@erkyrath
Last active November 28, 2017 15:38
Show Gist options
  • Save erkyrath/c71846f0c4544b2af12348bcf5b0e53f to your computer and use it in GitHub Desktop.
Save erkyrath/c71846f0c4544b2af12348bcf5b0e53f to your computer and use it in GitHub Desktop.
IFComp prize pool math
#!/usr/bin/env python3
# A quick script to compute the IFComp cash prize pool distribution
# under various conditions.
#
# Options:
#
# -p POOL size of prize pool (default=4800)
# -e ENTRIES number of entries (default=60)
# -m MINPRIZE minimum prize (default=10)
# -r ROUND round to multiples of this many cents (default=1)
#
# The default values assume we get 60 IFComp entries (with prizes to the
# top two-thirds, or the top 40). They also assume we reach our fundraising
# goal of $6000 (with 80% going to the prize pool, or $4800).
import sys
import optparse
from math import sqrt
popt = optparse.OptionParser(usage='prize.py [-p POOL] [-e ENTRIES] [-m MINPRIZE]')
popt.add_option('-p', '--pool',
action='store', dest='pool', type=float, default=4800.0,
help='size of prize pool (default=4800)')
popt.add_option('-e', '--entries',
action='store', dest='entries', type=int, default=60,
help='number of entries (default=60)')
popt.add_option('-m', '--min',
action='store', dest='minprize', type=float, default=10.0,
help='minimum prize (default=10)')
popt.add_option('-r', '--round',
action='store', dest='round', type=int, default=1,
help='round to multiples of this many cents (default=1)')
(opts, args) = popt.parse_args()
if args:
print('usage: %s' % (popt.usage,))
sys.exit(-1)
if (100 % opts.round):
raise Exception('rounding value must evenly divide 100')
pool = opts.pool
entries = opts.entries
minprize = opts.minprize
roundcents = float(100.0 / opts.round)
print('entries = %d; min prize = $%.02f; prize pool = $%.02f' % (entries, minprize, pool))
def plan():
n = int(0.6667 * entries)
max = 3.0 * (pool-minprize*n) / n
print('winners = %d; max prize = ~$%.02f' % (n, max))
def fn(x):
return 1.0*x*x - 2.0*x + 1.0
sum = 0
x = 1
while x <= n:
prize = max * fn((x-0.5)/n) + minprize
prize = int(roundcents*prize+0.5) / roundcents
print('%d: $%.02f' % (x, prize))
sum += prize
x += 1
print('Sum: $%.02f' % (sum,))
plan()
entries = 60; min prize = $10.00; prize pool = $4800.00
winners = 40; max prize = ~$330.00
1: $331.80
2: $315.71
3: $300.04
4: $284.78
5: $269.93
6: $255.49
7: $241.46
8: $227.85
9: $214.65
10: $201.86
11: $189.49
12: $177.53
13: $165.98
14: $154.84
15: $144.11
16: $133.80
17: $123.90
18: $114.41
19: $105.34
20: $96.68
21: $88.43
22: $80.59
23: $73.16
24: $66.15
25: $59.55
26: $53.36
27: $47.59
28: $42.23
29: $37.28
30: $32.74
31: $28.61
32: $24.90
33: $21.60
34: $18.71
35: $16.24
36: $14.18
37: $12.53
38: $11.29
39: $10.46
40: $10.05
Sum: $4799.30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment