Skip to content

Instantly share code, notes, and snippets.

@vettukal
Created October 14, 2023 05:04
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 vettukal/8e049533af136bf39c91ea3852756c66 to your computer and use it in GitHub Desktop.
Save vettukal/8e049533af136bf39c91ea3852756c66 to your computer and use it in GitHub Desktop.
more boy births in a small hospital vs big hospital per day
'''
A silly math question posed in our discord: There are two hospitals in a city,
a small and a bigger one. In which of them is the likelihood higher of
more boys than girls being born in one day?
(Provided that girls and boys are on average born equally frequently).
src: https://twitter.com/wagieeacc/status/1712958038871552020
'''
import random
SIMULATIONS = 1000
def simulate(beds):
total = 0
for i in range(beds):
coin = random.randrange(0,2)
if coin > 0:
total += 1
# print(total)
if total > beds // 2:
return 1
return 0
# when there are only 4 beds
gb = 0
small_beds = 8
for i in range(SIMULATIONS):
gb += simulate(small_beds)
print(f'number of greater boys in {small_beds} beds hosptial is {gb} out of 1000')
gb = 0
big_beds = 256
for i in range(SIMULATIONS):
gb += simulate(big_beds)
print(f'number of greater boys in {big_beds} beds hosptial is {gb} out of 1000')
'''
Output:
number of greater boys in 8 beds hosptial is 361 out of 1000
number of greater boys in 256 beds hosptial is 473 out of 1000
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment