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.

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.

Monty Hall Paradox Game Monty Hall Paradox Screen One Monty Hall Paradox

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.

PR Systems | Equipotentials | Convertor | Playlist Generator | ANT | LaTeX | Three Card Game | Notes/Presentations
Phone: 086 8068 764
Email  [email protected]  
Copyright © Me. 1993-2024 . All rights reserved.

Use Linux Apache Powered Get MySql PHP Powered Crafted using Vim Monitored with Piwik

Get Compatible Valid XHTML 1.0 Transitional Valid CSS!

 

 

Google Analytics Alternative