From f6c2d344b79b25caa0e34269536e745ac7f4e95f Mon Sep 17 00:00:00 2001 From: erbrown Date: Sun, 14 Dec 2025 19:13:43 -0500 Subject: [PATCH] An example could be playing cards. Each card is represented as a suit or value (1,2,3,4,...) and a deck is collection of cards. A player class can keep track of the cards and score. You could analyze or run the simulation multiple times to see which player wins the most or if a player is more likely to pick up a certain suit. --- dice_stats.py | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/dice_stats.py b/dice_stats.py index 83a99cb..02e08b2 100644 --- a/dice_stats.py +++ b/dice_stats.py @@ -18,16 +18,46 @@ class FiveDice: if face != 1: return False return True + + def face_counts(self): + counts = {} + for face in self.faces(): + if face in counts: + counts[face] += 1 + else: + counts[face] = 1 + return counts + + def is_three_of_a_kind(self): + for count in self.face_counts().values(): + if count >= 3: + return True + return False + + def is_four_of_a_kind(self): + for count in self.face_counts().values(): + if count >= 4: + return True + return False dice = FiveDice() -successes = 0 +all_ones_count = 0 +three_kind_count = 0 +four_kind_count = 0 trials = 1000000 for trial in tqdm(range(trials)): dice.roll() if dice.all_ones(): - successes += 1 + all_ones_count += 1 + if dice.is_three_of_a_kind(): + three_kind_count += 1 + if dice.is_four_of_a_kind(): + four_kind_count += 1 + +print("all ones:", all_ones_count/trials) +print("Three of a kind:", three_kind_count / trials) +print("Four of a kind:", four_kind_count / trials) -print(successes/trials)