diff --git a/dice_stats.py b/dice_stats.py index 83a99cb..af915f4 100644 --- a/dice_stats.py +++ b/dice_stats.py @@ -18,6 +18,41 @@ class FiveDice: if face != 1: return False return True + + def is_three_of_a_kind(self): + #set current roll of 5 dice to a list variable dice + dice = self.faces() + for die in range(len(dice)): + #take each roll value and compare it to the other values. + face_value = (dice[die]) + how_many = 0 + + for d in range(len(dice)): + #if the roll value is the same as another value, increase the count of how many + if die == face_value: + how_many +=1 + #if the cound of how many of that value is 3 or more, then you got three of a kind. So, return true. + if how_many >= 3: + return True + return False + + def is_four_of_a_kind(self): + #set current roll of 5 dice to a list variable dice + dice = self.faces() + for die in range(len(dice)): + #take each roll value and compare it to the other values. + face_value = (dice[die]) + how_many = 0 + + for d in range(len(dice)): + #if the roll value is the same as another value, increase the count of how many + if die == face_value: + how_many +=1 + #if the count of how many of that value is 4 or more, then you got three of a kind. So, return true. + if how_many >= 4: + return True + return False + dice = FiveDice() successes = 0 @@ -27,7 +62,27 @@ for trial in tqdm(range(trials)): if dice.all_ones(): successes += 1 -print(successes/trials) +print(f"All Ones: {successes/trials}") + +dice = FiveDice() +successes = 0 +trials = 1000000 +for trial in tqdm(range(trials)): + dice.roll() + if dice.is_three_of_a_kind(): + successes += 1 + +print(f"Three of a Kind: {successes/trials}") + +dice = FiveDice() +successes = 0 +trials = 1000000 +for trial in tqdm(range(trials)): + dice.roll() + if dice.is_four_of_a_kind(): + successes += 1 + +print(f"Four of a Kind: {successes/trials}")