몬테카를로 카지노 주사위
포스트 난이도: HOO_Middle
# Example Code
import random
import matplotlib.pyplot as plt
# Function to simulate die roll
def rolldice():
dice = random.randint(1, 100)
if dice <= 51:
return False
elif dice > 51:
return True
# Modified function for the play to return funds after each play
def play_mod(total_funds, wager_amount, total_plays):
Funds = []
for play in range(1, total_plays + 1):
if rolldice():
total_funds += wager_amount
else:
total_funds -= wager_amount
Funds.append(total_funds)
return Funds
# Finding the best number of bets for the highest ending fund
best_fund = -float('inf') # Initialize with a very low value
best_num_bets = 0
final_funds_for_each_bet = []
# Testing for up to 100 bets
for num_bets in range(1, 101):
final_funds = play_mod(10000, 100, num_bets)
final_fund = final_funds[-1]
final_funds_for_each_bet.append(final_fund)
if final_fund > best_fund:
best_fund = final_fund
best_num_bets = num_bets
# Output
print("Highest Ending Fund: $", best_fund, "achieved with", best_num_bets, "bets")
# Plotting
plt.plot(range(1, 101), final_funds_for_each_bet)
plt.ylabel('Player Money in $')
plt.xlabel('Number of bets')
plt.title('Final Funds after each Number of Bets')
plt.show()
# github Link
[Temp]
728x90
'Programming Languages > Python' 카테고리의 다른 글
[Python Examples] BeautifulSoup #01: 웹페이지 텍스트 크롤링 (0) | 2024.12.16 |
---|---|
[Python] Dask: Parallel Computing (0) | 2024.07.22 |
[Python] Random Seed(랜덤 시드) (0) | 2023.11.10 |
[Python Examples] Energy Flows: Compartments and Rate Coefficients (0) | 2023.09.29 |
[Python Examples] Simple Age-class Simulation (0) | 2023.09.29 |
댓글