An interactive graphical application for exploring the fascinating properties of Penney's Game, a counterintuitive coin-flipping game that demonstrates non-transitive probability.
Penney's Game is a two-player game where:
- Each player chooses a sequence of three coin flips (e.g., HHT, THH, HTT)
- A coin is flipped repeatedly until one player's sequence appears
- The player whose sequence appears first wins
The Surprise: The game is non-transitive - there's no single "best" pattern! For every pattern you choose, there exists a counter-pattern that beats it approximately 2/3 of the time.
- Waiting Times Paradox: HTT appears faster (~8 flips) than HTH (~10 flips) on average, even though both seem equally likely
- Optimal Strategy: Always let your opponent choose first, then pick the counter-pattern to win ~67% of games
- Non-Transitivity: Like rock-paper-scissors, but with coins - every pattern has a counter that dominates it
Calculates how many coin flips it takes on average for each pattern to appear:
- Reveals which patterns appear faster
- Explains the counterintuitive differences
- Demonstrates overlap effects
For each pattern, finds which opponent pattern beats it most effectively:
- Shows win rates for optimal counters
- Demonstrates that every pattern has a weakness
- Proves the ~67% advantage of counter-patterns
Complete 8×8 win-rate matrix for all pattern matchups:
- Color-coded cells (Green=Advantage, Red=Disadvantage, Yellow=Even)
- Shows all possible head-to-head results
- Visualizes the non-transitive structure
Game-theoretically optimal counter-strategies:
- Shows which pattern to pick against any opponent
- Explains the strategy rules
- Verifies win rates through simulation
Play matches between any two patterns:
- Select patterns for both players
- Simulate 1000 games instantly
- See which pattern dominates the matchup
- Python 3.x
- Tkinter (usually included with Python)
- Standard library modules:
random,itertools,threading
No installation required! Just run the script:
python3 penneys_game_gui.pyOr make it executable on Unix-like systems:
chmod +x penneys_game_gui.py
./penneys_game_gui.py- Select a Tab: Choose which aspect of the game to explore
- Set Parameters: Adjust the number of simulations (more = more accurate)
- Click "Run Analysis": Results appear in a few seconds
- Explore: Try different patterns and matchups
Default simulation counts can be adjusted at the top of the code:
DEFAULT_WAITING_TIME_SIMULATIONS = 10000 # Waiting time analysis
DEFAULT_MATCHUP_GAMES = 10000 # Best counter analysis
DEFAULT_MATRIX_GAMES = 10000 # Dominance matrix
DEFAULT_STRATEGY_GAMES = 5000 # Strategy verification
DEFAULT_INTERACTIVE_GAMES = 1000 # Interactive playThe counter-pattern is constructed to "intercept" the opponent's pattern. For example:
- Opponent picks: HTH
- Your counter: HHT
When coins show HT, your opponent needs an H to complete HTH. But if an H appears, you immediately complete HHT and win! This gives you a 2:1 advantage.
For any opponent pattern ABC:
- Take the second letter: B
- Prepend its opposite: opposite(B)
- Add the first letter: opposite(B) + A
Example: Opponent picks HTH → Take T, prepend H, add H = HHT
(Special cases for HHH and TTT use different rules)
The average waiting time for a pattern depends on its internal overlap structure. Patterns like HTT have less overlap than HTH, making them appear faster on average.
This application is perfect for:
- Probability Students: Exploring non-intuitive probability concepts
- Game Theory: Understanding non-transitive games
- Mathematics Education: Visualizing complex patterns
- Recreational Mathematics: Discovering surprising results
1. Open the "Waiting Times" tab
→ See that HTT (8 flips) appears faster than HTH (10 flips)
2. Check "Optimal Strategy" tab
→ Learn that HHT beats HTH 67% of the time
3. Try "Interactive Play"
→ Select HTH vs HHT
→ Simulate 1000 games
→ Confirm HHT wins ~670 times
4. Explore "Dominance Matrix"
→ See the complete web of advantages
→ Discover no pattern dominates all others
- Threading: All simulations run in background threads to keep the UI responsive
- Simulation Quality: Higher simulation counts provide more accurate results but take longer
- Color Coding: Green (>60% win rate), Red (<40%), Yellow (40-60%)
- Canvas-Based Matrix: Scrollable grid for the 8×8 dominance matrix
- Waiting Times: ~1-3 seconds (10,000 simulations per pattern)
- Best Counters: ~2-5 seconds (10,000 games per matchup)
- Dominance Matrix: ~10-20 seconds (28 unique matchups × 10,000 games)
- Strategy Analysis: ~2-5 seconds (8 matchups × 5,000 games)
- Interactive Play: Instant (1,000 games)
Penney's Game was first described by Walter Penney in 1969 and has since become a classic example in probability theory and game theory.
Key concepts demonstrated:
- Non-transitive games
- Conditional probability
- Pattern overlap
- Optimal decision theory
Free to use and modify for educational purposes.
Based on the mathematical work of Walter Penney and subsequent analysis by mathematicians exploring non-transitive games.
- Start with Waiting Times: Understand why patterns appear at different speeds
- Learn the Strategy: See how counter-patterns dominate
- Play Interactively: Test specific matchups you're curious about
- Study the Matrix: See the complete picture of all matchups
- Impress Your Friends: Challenge them to pick first, then win 2/3 of the time!