Skip to content

Instantly share code, notes, and snippets.

@readyready15728
Created November 28, 2021 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save readyready15728/48a3f2f6b08baf26dcf631fe57ccc4ed to your computer and use it in GitHub Desktop.
Save readyready15728/48a3f2f6b08baf26dcf631fe57ccc4ed to your computer and use it in GitHub Desktop.
The Ten Chests
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