• Zagorath@aussie.zone
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year 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%.

    • starman2112@sh.itjust.works
      link
      fedilink
      arrow-up
      0
      ·
      edit-2
      1 year ago

      There’ve been a lot of times when I simply didn’t believe something in statistics until I simulated it. Like this problem:

      I have two children. One is a boy born on a Tuesday. What is the probability I have two boys?

      I wanted to simulate that because the answer seems absurd. 13/27? Where does that even come from? I’m scared of snakes, so I use Baby’s First Programming Language: Tasker.

      1. Variable randomize %sex Min:1 Max:2

      2. Variable randomize %day Min:1 Max:7

      3. Variable set %child1 “%sex%day”

      4. Variable randomize %sex Min:1 Max:2

      5. Variable randomize %day Min:1 Max:7

      6. Variable set %child2 “%sex%day”

      7. Goto 1 IF %child1 != 11 AND %child2 != 11

      Now I’ve generated two random children, at least one of which is 11–a specific sex born on a specific day.

      1. Variable add %BoyGirl IF %child1 = 2* OR %child2 = 2*

      2. Variable add %BoyBoy IF %child1 = 1* AND %child2 = 1*

      If either child is a girl, it adds one to the BG bucket. If neither one is a girl, it adds one to the BB bucket.

      1. Variable add %Counter

      2. Goto 1 IF %Counter > 1,000

      Hit play and yep, about 48% of families were BB. But remove the Tuesday part and just simulate the question “I have two children, and at least one of them is a boy,” and it drops down to 33% again. I don’t understand it, but apparently the math maths.

      • Zagorath@aussie.zone
        link
        fedilink
        English
        arrow-up
        0
        ·
        1 year ago

        the math maths

        Ha. As someone from the “mathematics is shortened to maths” part of the world, this sounds weird to me. I’d probably say “the maths mathses”. I just thought you might enjoy that.

        Anyway, I Googled the problem you presented, and came across this excellent answer:

        There are even trickier aspects to this question. For example, what is the strategy of the guy telling you about his family? If he always mentions a boy first and not a daughter, we get one probability; if he talks about the sex of the first born child, we get a different probability. Your calculation makes a choice in this issue - you choose the version of “if the father has a boy and a girl, he’ll mention the boy”.

        What I’m aiming to is this: the question is not well-defined mathematically. It has several possible interpretations, and as such the “problem” here is indeed of the language; or more correctly, the fact that a simple statement in English does not convey enough information to specify the precise model for the problem.

        The whole answer is worth reading, but that part there is the crux of it. It goes back to one of my earliest comments on this topic in this thread. The problem isn’t that maths is weird, it’s that language’s ability to describe mathematical problems is lacking. There are so many different ways to translate the described problem into mathematical formulae and they necessarily carry assumptions. Even far more subtle assumptions than I at first thought.

        • nilloc@discuss.tchncs.de
          link
          fedilink
          English
          arrow-up
          0
          ·
          1 year ago

          I know this wasn’t the main point of your comment, but to be grammatically correct, it would be “the maths math.”

          Plural verbs go with their plural noun subject and don’t need the s:

          • This book belongs on the shelf.
          • These books belong on the shelf.

          And like you said, maths being short for mathematics means it’s plural.