Home | | | Software | | | Contact |
Three Card Game Paradox
Years ago I came across this three card game, it is where there is three cards, with a prize behind one card, and the player choses one card, then the computer removes one card which doesnt have the prize from the other two cards, and offers the player the chance to stay with the card they have chosen or change to the other card, the thing is most people stay and statistically this is not the best option since you are twice as likely to win by choosing to change. I wrote a program to play the game in BASIC (also fortran and pascal even cobol), and some years later in C and Perl, and then java, also run a simulation of a number of games to prove the statistical benefit of changing. Also a python version to simulate the paradox and to learn some python.
Results:
Sticking wins you 9973 times.
Changing wins you 20027 times.
Changing wins more times. 66% of the time.
- Three Card Paradox Simulation and Game LUA. Lua Code and Output (14/05/13).
- Three Card Paradox Simulation and Game Android App (21/02/13).
- Three Card Game Simulation in PHP (plays 1000 games)
- Three Card Game Simulation (plays 1000 games) (Python Code) Output (outputpy.txt) (19/02/13)
- Three Card Game Simulation Applet Specify Number of Simulations.
- Three Card Game Applet Play a Game (28/12/01).
- Three Card Game Simulation Java Swing (executable jar file)
- ThreeCardGame.java (Java Code) ThreeCardGame.class
- Three Card Game Simulation (PHP commandline Code) Output (outputphp.txt)
- Three Card Game Simulation (plays 1000 games) (Perl Code) Output (outputperl.txt) (28/12/01)
- Three Card Game Simulation (C Code) Output (outputc.txt) - (26/12/98)
- Three Card Game Simulation (FORTRAN Code) Output (outputf.txt)
- Three Card Game Simulation (COBOL Code) Output (text and record)
- Three Card Game Simulation (Pascal Code) Output (outputpas.txt) - not so random random numbers, originally written and compiled in Modula-2
This is actually called the "Monty Hall Paradox", after a US Game Show host, according to Mythbusters episode I seen recently (2011), they played the game a number of times to prove the theory. This promted me to dig it off my old PC hard drive, so Voila!
Conclusion
By playing the game a large number of times, you eventually find out that, switching (or twisting) is better than sticking with your original because your original card you select it out of three cards, however a twisted card is one of the other two cards, which is two out of three cards, hence staying will be 1/3 correct and twisting will be 2/3 correct!
Output:(LUA using lua50 on command line)
Game played 1000 times
Results:
Sticking wins 329 times (32.9%)
Twisting Wins 671 times (67.1%) .
End of Monty Hall Simulation
Output:(Perl using perl 5.8)
Game played 99 times
Results:
Sticking wins 26 (26.2626262626263 %)times
Twisting wins 73 (73.7373737373737 %) times
The End
Output:(C compiled using gcc)
Results:
Sticking wins: 42 times (37.500000 %)
Twisting wins: 70 times (62.500000 %)
It is better to twist.
The End
Output:(Fortran compiled using g77)
Results:
Sticking wins 336 times ( 33.5999985 %).
Changing wins 664 times ( 66.4000015 %).
Changing is better
The End!
Output:(Cobol compiled using opencobol/cobc)
*** Results ***
Game played 501 times.
Sticking wins 157 (31.33%) times, Twisting wins 344 (68.66%) times.
It's Better to Twist
*** End of Simulation! ***
Output:(Pascal compiled using gpc)
Results:
Game played 100 times
Sticking wins 37 times (37.00%)
Changing wins 63 times (63.00%)
Verdict:
Twisting wins more!
The End.
Output:(PHP compiled using PHP 5.2)
Results:
1000 Games
Switching wins 317 times (31.7 %)
Changing wins 683 times (68.3 %)
Verdict:
Its better to Change
The End
Output: (Python using python 2.5)
Results:
Sticking wins 355 times (35.5% )
Changing wins 645 times (64.5% )
Changing is better!
The End
Screenshots Android App.
Comments
I suppose this was a small program to learn a little bit about various languages. Often the most difficult thing was to get a random number generator particularly in the older languages (Cobol and Fortran), most of the programs there is some stats on the distribution of cards selected.The programs were all compiled using freely available compilers/interpreters for Linux(Ubuntu) with minor modifications from their original code which was specific to Turbo C MS Pascal, MF/PC Cobol etc.