Created
February 1, 2022 00:29
-
-
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.
This file contains 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 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