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)