Created
November 28, 2021 00:02
-
-
Save readyready15728/48a3f2f6b08baf26dcf631fe57ccc4ed to your computer and use it in GitHub Desktop.
The Ten Chests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import copy | |
import random | |
chests = [ | |
['D', 'D', 'D'], | |
['D', 'D', 'E'], | |
['D', 'D', 'R'], | |
['D', 'E', 'E'], | |
['D', 'E', 'R'], | |
['D', 'R', 'R'], | |
['E', 'E', 'R'], | |
['E', 'R', 'R'], | |
['E', 'E', 'E'], | |
['R', 'R', 'R'] | |
] | |
iterations = 100000 | |
found_at_least_one_diamond = 0 | |
found_two_diamonds = 0 | |
for _ in range(iterations): | |
# Not really necessary, but I abhor the idea of that jeweler's chests being disturbed! | |
chest = copy.copy(random.choice(chests)) | |
random.shuffle(chest) | |
if chest[0] == 'D': | |
found_at_least_one_diamond += 1 | |
if chest[0:2] == ['D', 'D']: | |
found_two_diamonds += 1 | |
print(found_two_diamonds / found_at_least_one_diamond) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment