Skip to content

Instantly share code, notes, and snippets.

@JasonGiedymin
Last active January 14, 2016 06:28
Show Gist options
  • Select an option

  • Save JasonGiedymin/0039a7ff694187a604a7 to your computer and use it in GitHub Desktop.

Select an option

Save JasonGiedymin/0039a7ff694187a604a7 to your computer and use it in GitHub Desktop.
quick n dirty powerball app done in python
# quick n dirty powerball app done in python
# wrote this in 30min (just look at the globals, tuples, string interpolation everywhere)
# not even sure if it's correct, probably won't play again due to odds ;-)
#
# outputs:
# $4, powerball match on ticket #0 [44, 47, 51, 57, 57], list: ([44, 47, 51, 57, 61], 10)
# $4, powerball match + 1 ball match on ticket #1 [*4, 47, 51, 57, 57], list: ([4, 47, 51, 57, 61], 10)
# $7, powerball match + 2 ball matches on ticket #2 [61, 47, 51, *8, *8], list: ([61, 47, 51, 8, 4], 10)
# $100, powerball match + 3 ball matches on ticket #3 [61, 47, *19, *8, *8], list: ([61, 47, 19, 8, 4], 10)
# $10000, powerball match + 4 ball matches on ticket #4 [61, *27, *19, *8, *8], list: ([61, 27, 19, 8, 4], 10)
# $9999999999, powerball match + 5 ball matches on ticket #5 [*34, *27, *19, *8, *8], list: ([34, 27, 19, 8, 4], 10)
# $7, 3 ball matches on ticket #6 [61, 47, *19, *8, *8], list: ([61, 47, 19, 8, 4], 11)
# $100, 4 ball matches on ticket #7 [61, *27, *19, *8, *8], list: ([61, 27, 19, 8, 4], 11)
# $1000000, 5 ball matches on ticket #8 [*34, *27, *19, *8, *8], list: ([34, 27, 19, 8, 4], 11)
#
x=[]
## My numbers
# with powerball
x.append(([44,47,51,57,61], 10))
x.append(([4,47,51,57,61], 10))
x.append(([61,47,51,8,4], 10))
x.append(([61,47,19,8,4], 10))
x.append(([61,27,19,8,4], 10))
x.append(([34,27,19,8,4], 10))
# without powerball
x.append(([61,47,19,8,4], 11))
x.append(([61,27,19,8,4], 11))
x.append(([34,27,19,8,4], 11))
# Winning Numbers
master=([4,8,19,27,34], 10)
power_play=2
power_play_played=False
def payout(pb, matches):
bank = [
{3:7, 4:100, 5:1000000}, # no pb
{0:4, 1:4, 2:7, 3:100, 4:10000, 5:9999999999} # yes pb
]
pp_modifier = power_play if power_play_played else 1
return bank[pb].get(matches) * pp_modifier
def highlight(markers, numbers):
def next(num):
return "*%d" % num if num in markers else "%d" % num
sequence = [next(numbers[i]) for i in range(0, len(numbers))]
return ", ".join(sequence)
def wins(pb, matches, ticket_id, master, list, full):
def get_pb():
return "powerball match" if pb else ""
def get_ball(n):
if matches == 1:
return "%d ball match" % n
elif matches > 1:
return "%d ball matches" % n
else:
return ""
def get_modifer():
return " + " if pb and matches > 0 else ""
msg="%s $%d, %s%s%s on ticket #%d [%s], list: %s"
print msg % ("", payout(pb, matches), get_pb(), get_modifer(), get_ball(matches), ticket_id, highlight(master, list), full)
for n, list in enumerate(x):
pb_match = master[1] == list[1]
matches = len([1 for i in list[0] if i in master[0]])
if pb_match and matches <= 5:
wins(pb_match, matches, n, master[0], list[0], list)
elif not pb_match and (3 <= matches <= 5):
wins(pb_match, matches, n, master[0], list[0], list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment