From 1f25c861129992b1f64b96f86d7c806541d14bbc Mon Sep 17 00:00:00 2001 From: bpot Date: Thu, 23 Apr 2026 11:17:28 -0400 Subject: [PATCH] i did it yoooooo --- .envrc | 1 + dice_stats.py | 81 ++++++++++++++++++++++++++++++++++++++++++++++++--- poetry.lock | 56 +++++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+), 4 deletions(-) create mode 100644 .envrc create mode 100644 poetry.lock diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..4a96c22 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +source .venv/bin/activate \ No newline at end of file diff --git a/dice_stats.py b/dice_stats.py index 83a99cb..740570d 100644 --- a/dice_stats.py +++ b/dice_stats.py @@ -13,21 +13,94 @@ class FiveDice: def faces(self): return [die.face for die in self.dice] + def value_count(self): + + ones = 0 + twos = 0 + threes = 0 + fours = 0 + fives = 0 + sixes = 0 + + for face in self.faces(): + if face == 1: + ones += 1 + if face == 2: + twos += 1 + if face == 3: + threes += 1 + if face == 4: + fours += 1 + if face == 5: + fives += 1 + if face == 6: + sixes += 1 + + count = {"ones": ones, "twos": twos, "threes": threes, "fours": fours, "fives": fives, "sixes": sixes} + return count + def all_ones(self): for face in self.faces(): if face != 1: return False return True + def is_three_of_a_kind(self): + count = self.value_count() + if count["ones"] == 3: + return True + if count["twos"] == 3: + return True + if count["threes"] == 3: + return True + if count["fours"] == 3: + return True + if count["fives"] == 3: + return True + if count["sixes"] == 3: + return True + else: + return False + + def is_four_of_a_kind(self): + count = self.value_count() + if count["ones"] == 4: + return True + if count["twos"] == 4: + return True + if count["threes"] == 4: + return True + if count["fours"] == 4: + return True + if count["fives"] == 4: + return True + if count["sixes"] == 4: + return True + else: + return False + dice = FiveDice() -successes = 0 +successes_all_ones = 0 +successes_is_three_of_a_kind = 0 +successes_is_four_of_a_kind = 0 trials = 1000000 for trial in tqdm(range(trials)): dice.roll() if dice.all_ones(): - successes += 1 - -print(successes/trials) + successes_all_ones += 1 + if dice.is_three_of_a_kind(): + successes_is_three_of_a_kind += 1 + + if dice.is_four_of_a_kind(): + successes_is_four_of_a_kind += 1 +""" +print(successes_all_ones/trials , successes_is_three_of_a_kind/trials , successes_is_four_of_a_kind/trials) +""" +print( + f"All ones: {successes_all_ones/trials:.6f}, " + f"Three of a kind: {successes_is_three_of_a_kind/trials:.6f}, " + f"Four of a kind: {successes_is_four_of_a_kind/trials:.6f}" +) diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..3c9b5fe --- /dev/null +++ b/poetry.lock @@ -0,0 +1,56 @@ +# This file is automatically @generated by Poetry 2.3.1 and should not be changed by hand. + +[[package]] +name = "click" +version = "8.3.1" +description = "Composable command line interface toolkit" +optional = false +python-versions = ">=3.10" +groups = ["main"] +files = [ + {file = "click-8.3.1-py3-none-any.whl", hash = "sha256:981153a64e25f12d547d3426c367a4857371575ee7ad18df2a6183ab0545b2a6"}, + {file = "click-8.3.1.tar.gz", hash = "sha256:12ff4785d337a1bb490bb7e9c2b1ee5da3112e94a8622f26a6c77f5d2fc6842a"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} + +[[package]] +name = "colorama" +version = "0.4.6" +description = "Cross-platform colored terminal text." +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +groups = ["main"] +markers = "platform_system == \"Windows\"" +files = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] + +[[package]] +name = "tqdm" +version = "4.67.1" +description = "Fast, Extensible Progress Meter" +optional = false +python-versions = ">=3.7" +groups = ["main"] +files = [ + {file = "tqdm-4.67.1-py3-none-any.whl", hash = "sha256:26445eca388f82e72884e0d580d5464cd801a3ea01e63e5601bdff9ba6a48de2"}, + {file = "tqdm-4.67.1.tar.gz", hash = "sha256:f8aef9c52c08c13a65f30ea34f4e5aac3fd1a34959879d7e59e63027286627f2"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} + +[package.extras] +dev = ["nbval", "pytest (>=6)", "pytest-asyncio (>=0.24)", "pytest-cov", "pytest-timeout"] +discord = ["requests"] +notebook = ["ipywidgets (>=6)"] +slack = ["slack-sdk"] +telegram = ["requests"] + +[metadata] +lock-version = "2.1" +python-versions = ">=3.10,<4.0" +content-hash = "bb89287de0cafdf48a8eea6717121a79981ba4c7811aca416921cceb4f89f67b"