CodePlexProject Hosting for Open Source Software

A university project explaining a phenomenon of a coin tossing game called Penney Ante.

This project has been originally written in Mathematica. Parts of the original project have been later rewritten in Java as a simple frame application.

So what is so interesting about Penney Ante? There are eight different patterns to consider (HHH, HHT, HTH, HTT, THH, THT, TTH, TTT). Each pattern is built of outcomes of three tosses. Each of the three outcomes is equally likely to happen and independent of the others. Hence if we throw a coin three times each pattern has the same probability of winning (1/8). At this stage it´s intuitive to think about the patterns as independent and the game to be fair. This logic would be perfectly fine if after each three throws we could follow with another three and continue in that manner until one of the players wins. However, Penney-ante is not played that way. If after first three flips there is no winner, we do a fourth toss and we examine the last three throws. If there is still no winner, we do a fifth throw, and we continue until a winning pattern is matched. Therefore patterns depend on previous flips which makes them depend on each other. Thus at least some of them when played against each other appear first with different probabilities.

Although initially the game appears to be fair, it is not in general. Results appear to be quite surprising. There is no best pattern that beats all others. The best we can do is let our opponent go first and then choose the best possible option that beats his particular pattern. To do so we need to be able to define relations between each two patterns. Thus we would like to invent a function which calculates the probability of one pattern happening before another. Moreover, we obviously want to come up with a function that can cope with any pattern length. And this is where the fun begins. As we will see it is a lot easier to solve the problem using a pencil and a piece of paper than writing a programming code.

- a short description of the problem illustrated by various graphs.

- a source code of a function originally written to deal with patterns of length three and a function modified to deal with any pattern length.

It also gives a chance to run the universal function for all 28 possible pairs of patterns of length three, display results and view a short description.

The project has been originally written in Mathematica. The original Mathematica project not only explains how to find probabilities of some patterns to appear before others but also includes:

- computations of the average waiting time for each of the 8 considered patterns to happen.

- game simulations that test the correctness of the computations by running the game a various number of times.

- a simple frame application that lets you play the game and convince yourself that you have no chance playing against a machine while going first and how easy it is to win having a second choice.

You can display the whole Mathematica project in PDF as well as in an interactive .nb format. Open .nb file using Mathematica. You can also open .nb files using CDF Player but in this case .nb files will not function interactively. Both Mathematica and CDF Player can be downloaded from http://www.wolfram.com/

- complete application with all the source code as well as jar and exe files.

- exe file only.

To run the application use CoinGames.jar or CoinGames.exe.

programming language: Java

Last edited Jan 19, 2013 at 1:56 PM by panryba, version 22