Skip to content

Instantly share code, notes, and snippets.

@TheEnquirer
Created February 1, 2022 00:29
Show Gist options
  • Save TheEnquirer/41dc4a2b4b87aaa60e8ab2baf48b5c9d to your computer and use it in GitHub Desktop.
Save TheEnquirer/41dc4a2b4b87aaa60e8ab2baf48b5c9d to your computer and use it in GitHub Desktop.
Quick simulation for a problem from the Advanced Probability class at my school.
import random # imports
ITER = 100_000 # iteration count
a_guilty = b_guilty = 0 # initialize our counters
for _ in range(ITER):
# initialize our profiles
# [has blood type x, is guilty]
profiles = [[True, 1], [((random.randint(1,10)) == 1), 0]]
# assign our profiles to a and b randomly
a, b = ((profiles[0], profiles[1]), (profiles[1], profiles[0]))[random.randint(0,1)]
if not a[0]: continue # if a does not have blood type x, then skip this iteration
# update our counters
a_guilty += a[1]
b_guilty += b[1]
# finally, print out our results.
print(a_guilty/(a_guilty+b_guilty))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment