Powerball Earnings

See how much money you would have earned with Powerball lottery if you played with the same set of numbers since the beginning of the game. This is a very simple script, with no number validation.

Enter the 5 “White Balls” numbers followed by the Powerball number.

Examples:

$ python powerball.py 33 10 13 57 41 14
WB: [33, 10, 13, 57, 41]
PB: 14
Total Money Prize:  274
Total Money Paid:  3798
Max Money Prize:  7
$ python powerball.py 67 52 47 16 8 9
WB: [67, 52, 47, 16, 8]
PB: 9
Total Money Prize:  205
Total Money Paid:  3798
Max Money Prize:  7

Data: http://www.powerball.com/powerball/winnums-text.txt

Python script:


import sys, argparse
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

parser = argparse.ArgumentParser(description=‘Powerball Analyzer’) parser.add_argument(‘numbers’, metavar=‘N’, type=int, nargs=‘+’,) args = parser.parse_args()

k=[args.numbers[0:5],args.numbers[5]] print "WB:", k[0] print "PB:", k[1]

data = pd.read_csv("winnums-text.txt", delim_whitespace=True, header=None, skipinitialspace=True, skiprows=1, names=["DrawDate", "WB1", "WB2", "WB3", "WB4", "WB5", "PB", "PP"])

prizes={(5,True): 1000000000, (5,False): 1000000, (4,True): 50000, (4,False): 100, (3,True): 100, (3,False): 7, (2,True): 7, (1,True): 4, ​ (0,True):4, (0,False):0}

wblist = data.ix[:,1:6].stack().tolist()

plt.yscale(‘log’, nonposy=‘clip’) plt.hist(wblist, bins=68)

wb=data.ix[:,1:6] pb=data[‘PB’]

res_wb = wb.apply(lambda x: set(x) & set(k[0]), axis=1).icol(0).apply(len) res_pb = pb == k[1]

res = pd.DataFrame(zip(res_wb,res_pb))

money_prizes = res.apply(lambda x: prizes.setdefault ( (x[0], x[1]), 0 ) , axis=1)

total_money_prize = sum(money_prizes) total_paid = 2*len(data) max_prize = max(money_prizes)

print "Total Money Prize: ", total_money_prize print "Total Money Paid: ", total_paid print "Max Money Prize: ", max_prize ```