diff --git a/__pycache__/die.cpython-310.pyc b/__pycache__/die.cpython-310.pyc new file mode 100644 index 0000000..433e7f0 Binary files /dev/null and b/__pycache__/die.cpython-310.pyc differ diff --git a/dice_stats.py b/dice_stats.py index 83a99cb..d051195 100644 --- a/dice_stats.py +++ b/dice_stats.py @@ -1,5 +1,6 @@ from die import Die from tqdm import tqdm +from collections import Counter class FiveDice: def __init__(self): @@ -19,15 +20,34 @@ class FiveDice: return False return True + def is_three_of_a_kind(self): + listOfFaces = self.faces() + listOfFaces.sort() + if listOfFaces[0] == listOfFaces[1] and listOfFaces[0] == listOfFaces[2]: + return True + elif listOfFaces[1] == listOfFaces[2] and listOfFaces[1] == listOfFaces[3]: + return True + elif listOfFaces[2] == listOfFaces[3] and listOfFaces[2] == listOfFaces[4]: + return True + else: + return False + + def is_four_of_a_kind(self): + listOfFaces = self.faces() + listOfFaces.sort() + if listOfFaces[0] == listOfFaces[3]: + return True + elif listOfFaces[1] == listOfFaces[4]: + return True + else: + return False + dice = FiveDice() successes = 0 trials = 1000000 for trial in tqdm(range(trials)): dice.roll() - if dice.all_ones(): + if dice.is_three_of_a_kind(): successes += 1 print(successes/trials) - - - diff --git a/pyproject.toml b/pyproject.toml index c873876..c54d940 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ readme = "README.md" packages = [{include = "lab_dice"}] [tool.poetry.dependencies] -python = "^3.11" +python = "^3.10" click = "^8.1.6" tqdm = "^4.66.1"