Created
March 18, 2024 02:45
-
-
Save tomlockwood/85e7a3e95ba89a789f3acb1d0ffecb81 to your computer and use it in GitHub Desktop.
Seat configurations based on proportions
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
enf = 0.788 # Change this for different probabilities | |
disenf = 1 - enf | |
# Change this number for different numbers of members per body | |
SEATS = 14 | |
total = 0 | |
probability_per = {k: 0 for k in range(SEATS + 1)} | |
# We generate a binary number for each configuration of seats | |
# So for a 2 seat body we get 00 01 10 11 - representing all possible | |
# configurations. This could have been done more easily but I don't | |
# know the technique and don't care. | |
for i in range(2**SEATS): | |
binary = bin(i)[2:] | |
pad = "0" * (SEATS - len(binary)) | |
prob = 1 | |
per = 0 | |
padded = pad + binary | |
for y in padded: | |
if y == str(1): | |
prob *= disenf | |
else: | |
prob *= enf | |
per += 1 | |
total += prob | |
probability_per[per] += prob | |
# Used this for debugging | |
print(total) | |
# This is the dictionary of configurations | |
print(probability_per) | |
for k, v in probability_per.items(): | |
print(k, v) # For importing into Excel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment