I just submitted an answer to this question, and then looked about at some news stories about the MegaMillions lottery craze going on right now in the US. This news article stated that an individual purchased $20,000 worth of tickets at one time (that's 20,000 sets of numbers to confirm!) to try and test their luck.
That led me to thinking about how one might quickly determine whether or not they'd won any prize, not just a jackpot, on a large lot of tickets that they had purchased.
The challenge then is this:
Overview:
Write a function or program that will accept a string of numbers as an argument (STDIN, or read in from a file, your choice), and return the numbers of the tickets with at least the minimum payout awarded.
Code Details:
- The input will consist of a series of lines, one for each ticket purchased. The winning numbers will be prefixed with a 0, while the drawn numbers will be prefixed with an incremented number starting at 1. (see example)
- The input should be a completely random set of numbers each time, including draws and winning numbers.
- The input should accept any number of tickets n where 1 <= n <= 20,000. (Assume no 0 ticket runs.)
- Each line of input will have 7 numbers per line. One for the prefix noted above, 5 for the standard balls, and one additional for the 'match' ball. (see Lotto Details below)
- The input can be delimited any way you wish (whitespace, semicolon, etc.)
- The output should be a listing of all winning draws and the winning amount. (So you know which to turn in.)
- The output listing should be ordered by win amount. (Who cares if you won $2 on one ticket if you also won $10,000 on another???)
- When more than one ticket wins the same amount, the order of those tickets is irrelevant.
- The output should also give a listing of the total amount won.
Lotto Details:
- Standard rules for the MegaMillions game will apply, since that's what's so hot right now.
- Draws consist of six numbers from two separate pools of numbers - five different numbers from 1 to 56 and one number (the match ball) from 1 to 46.
- The jackpot is won by matching all six winning numbers in a drawing.
Awards for non-jackpot wins are awarded as follows (see image below).
(Main) + (Match) = (Payout)
5 + 1 = Jackpot
5 + 0 = $250,000
4 + 1 = $10,000
4 + 0 = $150
3 + 1 = $150
3 + 0 = $7
2 + 1 = $10
1 + 1 = $3
0 + 1 = $2Assume current jackpot is $1,000,000 (one million).
- Assume only one jackpot winner, unless your random draw pulls the same jackpot pick more than once (are you cheating?).
- Assume no multiplier/California rules are in-play.
Challenge Details:
- This is code golf, so shortest code wins.
- In the event of a tie, I'll take the highest upvoted answer. I know this is somewhat subjective, but the main point is still the score.
Example:
Input:
0 2 4 23 38 46 23
1 17 18 22 23 30 40
2 2 5 24 37 45 23
3 4 23 38 40 50 9
4 2 4 23 38 46 17
5 5 16 32 33 56 46
Output:
4 - $250,000
3 - $7
2 - $3
Total Winnings: $250,010