Yesterday (24th Feb 2015), the online MMORPG Final Fantasy XIV launched a patch that included, among many other things, the Mini-Cactpot lottery, a sort of scratchcard lottery that isn’t entirely dependent on luck. Here is a short summary of the rules, pasted from the patch notes:
Every ticket has nine spaces, each numbered randomly from one to nine. At the start, however, eight of these nine spaces will be hidden. To begin, select three numbers from the eight hidden on your ticket. Next, select one of eight lines─vertical, horizontal, or diagonal. When selecting a line, the sum of the three numbers in that line will determine the amount of MGP you receive.
Common sums receive smaller amounts of “MGP” (the currency) whereas the rarest sum (6, which can you can only get with a line of 1, 2, 3) gets the grand prize of 10000. As you can see in the rules, 4 of the 9 values will be un-hidden meaning you can calculate all combinations of what each line (column, row, diagonal) can produce and find which line gives the better odds of landing on a sum with a higher payout. It all just depends on where the 4 initial un-hidden numbers were and what numbers they were. After that it’s just a very large amount of sums, finding the payouts for each of these sums and calculating the average payout for each line. Simple to do on paper but very time consuming and tedious.
So I wrote a program that does it all for me.
It asks the user to input the un-hidden numbers and place them into the correct positions and then:
- Finds out which numbers weren’t used in the initial un-hiding stage. These are the numbers used to generate all possible combinations with the un-hidden numbers
- For each of the 8 lines (3 columns, 3 rows, 2 diagonals), find out how many hidden numbers (denoted by a value of 0) remain.
- If there are 0 hidden numbers, there is only 1 combination and the sum & payout are easy to calculate
- If there is 1 hidden number, sum the 2 un-hidden ones in that line and find all 5 combinations between the two known numbers and each of the 5 unknown numbers
- If there are 2 or 3 hidden numbers, we do practically the same thing but the generation of all possible sums (and their payouts) is a little more complex. 2 hidden values requires a loop within a loop and 3 hidden values requires a loop within a loop within a loop but is still overall not too complex.
- Prints out all the sums and payouts for each line along with the average (mean) payout
Note that you can’t guarantee a great win at all, random is still random, luck is still luck but this helps steer you towards the lines which are more likely to give a higher payout.
A picture of it in action. The zeroes correspond to the unknown hidden values and the 4 non-zero values are the 1 value the game gives me and the results of the 3 choices I get to unveil more values.
Click on the image to make it larger and more legible.
As we can see from the output, there are two lines (row 2 and the diagonal going from top-right to bottom-left) that are much more likely to give me better prizes than the other lines. Row 2 technically has the highest expected payout but it also has a lot of very small payouts (36 is the worst and there are multiple 36 payouts) whereas the diagonal line has a smaller average but at worst will give 72, twice the smallest in row 2. So seeing both the average payout and also all of the possible payouts allows you to reason more easily which line you want to choose to maximise your odds of getting a good payout.
In the future I intend to produce a visual version of the program using C# and WPF but at the moment my time is taken up by work and my studies on Haskell and the Unreal Engine 4. A post about Haskell and some stuff I’ve written with it will hopefully appear soon.
As with all my other projects, if you wish to see the source code then please email me at the address specified on my C.V if and only if I have applied to your company and I would be more than happy to show you.