• Zagorath@aussie.zone
    link
    fedilink
    English
    arrow-up
    1
    ·
    11 months ago

    I put it together. Here’s the code I wrote in Python.

    import random
    
    genders = ['boy', 'girl']
    
    def run():
        other_child_girls = 0
        for i in range(10000):
            other_child = get_other_child()
            if other_child == 'girl':
                other_child_girls += 1
        print(other_child_girls)
    
    def get_other_child():
        children = random.choices(genders, k=2)
        first_child_index = random.randint(0, 1)
        first_child = children[first_child_index]
        if first_child == 'boy':
            other_child_index = (first_child_index + 1) % 2
            return children[other_child_index]
        # Recursively repeat this call until the child at the door is a boy
        # (i.e., discard any cases where the child at the door is a girl)
        return get_other_child()
    
    if __name__ == '__main__':
        run()
    

    And it turns out you were right. I ran it a few times and got answers ranging from 4942 to 5087, i.e., clustered around 50%.