Nov-20-2020, 05:32 AM
(This post was last modified: Nov-20-2020, 05:32 AM by deanhystad.)
I think the averages in your last post look fine. 1000 hands is a pretty small sample size for this game as the number of hands required to win or lose varies greatly. I modified my program slightly to collect the counts and do a little statistical analysis and plotting.
What I found really interesting is how bad this game is. You never win. I modified the code to count wins and losses and I never win. I guess this makes sense considering you only have a 38% chance of winning any given hand and you need to win a lot of hands to double your money. The odds are not in your favor.
import random import statistics import collections import matplotlib.pyplot as plt deck = 'A234567890JQK'*4 hand = 6 def play(start): count = 0 bank = start while 0 < bank < start*2: if 'A' in random.sample(deck, hand): bank += 1 else: bank -= 1 count += 1 return count while True: start = int(input('Enter inital amount: ')) counts = [play(start) for _ in range(1000)] unique_counts = collections.Counter(counts) print('Mean =', statistics.mean(counts)) print('Median =', statistics.median(counts)) print('Number of different counts =', len(unique_counts)) print('Count range =', min(counts), 'to', max(counts)) mode = statistics.mode(counts) print('Mode =', mode, 'Count =', unique_counts[mode]) print('Standard Deviation =', statistics.stdev(counts)) plt.bar(unique_counts.keys(), unique_counts.values()) plt.show()
Output:Enter inital amount: 100
Mean = 484.818
Median = 474.0
Number of different counts = 222
Count range = 238 to 952
Mode = 454 Count = 15
Standard Deviation = 103.47417929987066
Enter inital amount: 100
Enter inital amount: 100
Mean = 492.046
Median = 480.0
Number of different counts = 227
Count range = 250 to 934
Mode = 466 Count = 15
Standard Deviation = 102.92227591186895
Running two tests the average count changed from 484 to 492. Such variation is not surprising when you see the number of hands required to win or lose a game ranges from the low 200's to over 1000 upon occasion. When I increased the sample size from 1000 to 10,000 I also noticed some interesting clumping in the plots. The kind of non-uniform distribution that raises hell with statistical analysis.What I found really interesting is how bad this game is. You never win. I modified the code to count wins and losses and I never win. I guess this makes sense considering you only have a 38% chance of winning any given hand and you need to win a lot of hands to double your money. The odds are not in your favor.