From 35a8bd78ae7863fcbc86ac4ed3a441077b79b23f Mon Sep 17 00:00:00 2001 From: Pat Wick Date: Wed, 31 Jan 2024 20:13:01 -0500 Subject: [PATCH] Added is_three_of_a_kind and is_four_of_a_kind Checkpoint 1: The first thing that comes to my mind, along the same vein as the Die objects, is a deck of cards. You could create a deck of Card objects and deal hands to simulate poker or blackjack. --- __pycache__/die.cpython-310.pyc | Bin 0 -> 724 bytes dice_stats.py | 22 +++++++++++++++++++++- poetry.lock | 10 +++++----- pyproject.toml | 2 +- 4 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 __pycache__/die.cpython-310.pyc diff --git a/__pycache__/die.cpython-310.pyc b/__pycache__/die.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..61321f2b890e8855e20567ed507d221d7df3e701 GIT binary patch literal 724 zcmZ`%y^hpC47O*IY*?~Fx)zCwCKMMT3L1n?0*P*$?Y0?(c#az`KgT4i6|3#`9t6sL zrJn>~Dk?|@8i1xH*mfyj4tedM#Z_4N^a%2~f&7dKsFi@U9> zZi}Y8b?qm!b;FIRImx=(?<|PxxizHyMElGh;Zx7-??Ao8#{Bgg3tb11DP= z$8o`zfwx5Jp!Q%;fO(2~d6KD}1T0rxTJTc*A#@*e;0bFlWHU@~mkPFwbeShIjkav8 zF=1{@)6u4uduGg+O<7M7FJ1eE7%6tvo-D#kk6tK?*NaIZ#Z+f{d|l=`B=QG!&BRnv SAF2`3HxvF_X>Ot$U#Q>s{Duqw literal 0 HcmV?d00001 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"