diff --git a/__pycache__/die.cpython-310.pyc b/__pycache__/die.cpython-310.pyc new file mode 100644 index 0000000..61321f2 Binary files /dev/null and b/__pycache__/die.cpython-310.pyc differ diff --git a/dice_stats.py b/dice_stats.py index 83a99cb..3d5cc0d 100644 --- a/dice_stats.py +++ b/dice_stats.py @@ -18,13 +18,33 @@ class FiveDice: if face != 1: return False return True + + def is_three_of_a_kind(self): + self.faces().sort() + if self.faces()[0] == self.faces()[1] and self.faces()[0] == self.faces()[2] and self.faces()[0] != self.faces()[3]: + return True + elif self.faces()[1] == self.faces()[2] and self.faces()[1] == self.faces()[3] and self.faces()[1] != self.faces()[4]: + return True + elif self.faces()[2] == self.faces()[3] and self.faces()[2] == self.faces()[4]: + return True + else: + return False + + def is_four_of_a_kind(self): + self.faces().sort() + if self.faces()[0] != self.faces()[4] and self.faces()[0] == self.faces()[1] and self.faces()[0] == self.faces()[2] and self.faces()[0] == self.faces()[3]: + return True + elif self.faces()[0] != self.faces()[1] and self.faces()[1] == self.faces()[2] and self.faces()[1] == self.faces()[3] and self.faces()[1] == self.faces()[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_four_of_a_kind(): successes += 1 print(successes/trials) diff --git a/poetry.lock b/poetry.lock index ab80980..6b66509 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2,13 +2,13 @@ [[package]] name = "click" -version = "8.1.6" +version = "8.1.7" description = "Composable command line interface toolkit" optional = false python-versions = ">=3.7" files = [ - {file = "click-8.1.6-py3-none-any.whl", hash = "sha256:fa244bb30b3b5ee2cae3da8f55c9e5e0c0e86093306301fb418eb9dc40fbded5"}, - {file = "click-8.1.6.tar.gz", hash = "sha256:48ee849951919527a045bfe3bf7baa8a959c423134e1a5b98c05c20ba75a1cbd"}, + {file = "click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28"}, + {file = "click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"}, ] [package.dependencies] @@ -47,5 +47,5 @@ telegram = ["requests"] [metadata] lock-version = "2.0" -python-versions = "^3.11" -content-hash = "e78479d542c88ba0a220d425c59162a0f8c7ecfef5c42eb296d1431c0ab05b87" +python-versions = "^3.10" +content-hash = "20affb522c68abead0ebbdc99087c61d83c1efa06367c5a707a0153e8581679c" 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"