
Lets start. This game will now run only once (a single simulation), and the number of rounds is 80 to represent 80 years (assuming each round is a year). The setup remains the same: 10,000 players start with $10,000 each, with the first 10 players having a 60% chance of good outcomes (+20%), the last 10 players having a 40% chance, and the rest at 50%. After 80 rounds, it will output the top 20 players and count how many have $0.
Here’s the code:
import random
import numpy as np
# Set random seed for reproducibility (optional)
random.seed(42)
# Game parameters
num_players = 10000
initial_amount = 10000
num_rounds = 80 # Changed to 80 rounds (80 years)
default_good_prob = 0.5 # Default 50% chance for good thing
clever_good_prob = 0.6 # 60% chance for first 10 players
unlucky_good_prob = 0.4 # 40% chance for last 10 players
# Initialize players with $10,000 each
players = [initial_amount] * num_players
# Simulate the game for 80 rounds
for round in range(num_rounds):
for i in range(num_players):
if players[i] > 0: # Only update if player still has money
# Determine player's good thing probability
if i < 10: # First 10 players (clever)
good_prob = clever_good_prob
elif i >= num_players - 10: # Last 10 players (unlucky)
good_prob = unlucky_good_prob
else: # Default players
good_prob = default_good_prob
# Simulate outcome
outcome = random.random() # Random number between 0 and 1
if outcome < good_prob:
# Good thing: +20%
players[i] *= 1.2
else:
# Bad thing: -20%
players[i] *= 0.8
# Ensure amount doesn't go below 0
if players[i] < 0.01: # Small threshold to treat as $0
players[i] = 0
# After 80 rounds, analyze results
# Create a list of (player_number, amount) pairs
player_results = [(i + 1, amount) for i, amount in enumerate(players)]
# Sort players by amount in descending order
player_results.sort(key=lambda x: x[1], reverse=True)
# Get top 20 players
top_20 = player_results[:20]
# Count players with $0 (or effectively $0)
zero_count = sum(1 for amount in players if amount < 0.01)
# Output results
print("Top 20 Players after 80 rounds (80 years):")
print("Player Number | Amount")
print("------------------------")
for player_num, amount in top_20:
print(f"Player {player_num:>5} | ${amount:,.2f}")
print("\nSummary:")
print(f"Number of players with $0: {zero_count}")
# Additional info: max and min amounts
max_amount = max(players)
min_amount = min(players)
print(f"Highest amount: ${max_amount:,.2f}")
print(f"Lowest amount: ${min_amount:,.2f}")
# Check performance of clever and unlucky players
clever_avg = sum(players[:10]) / 10
unlucky_avg = sum(players[-10:]) / 10
print(f"\nAverage amount for first 10 clever players (60% good): ${clever_avg:,.2f}")
print(f"Average amount for last 10 unlucky players (40% good): ${unlucky_avg:,.2f}")
After 80 years, the script still shows:
- The top 20 players by amount.
- The number of players with $0.
- The highest and lowest amounts.
- The average amounts for the clever (1–10) and unlucky (9991–10000) players.
Let see the result after 80 years, which player will fit into top 10:
Log in to unlock the full content and continue reading.