Hacker News new | ask | show | jobs
by QasimK 870 days ago
Super confusing! Through different reasoning I get different answers:

1. More likely to be red because the urn has a greater chance of having more red balls

2. Equally likely by considering all remaining urn possibilities to be equally likely

3. More likely to be green because obviously there is one less red ball than before

I wrote a Python program to simulate the problem. It tells me that the correct answer is (2) - it's equally likely that the next ball is red or green.

I wonder if I've made a mistake, or if that's really the real answer!

    #!/usr/bin/python
    import random
    from collections import Counter
    
    def experiment():
        urn = random.choices(["R", "G"], k=100)
        if urn.pop() != "R":
            return
    
        return urn.pop()
    
    results = (experiment() for i in range(1_000_000))
    results = (result for result in results if result is not None)
    print(Counter(results))
EDIT: I did make a mistake! The above produces a binomial distribution of urns with red/green. As in, the most common urn is one with an equal number of reds and greens, and the least common is all reds or all greens. Whereas they should have equal probability. To actually match the question:

    #!/usr/bin/python
    import random
    from collections import Counter
    
    def experiment():
        num_red = random.randint(1, 100)
        num_green = 100 - num_red
        urn = ["R"] * num_red + ["G"] * num_green
        random.shuffle(urn)
        if urn.pop() != "R":
            return
    
        return urn.pop()
    
    results = (experiment() for i in range(1_000_000))
    results = (result for result in results if result is not None)
    print(Counter(results))

The answer is indeed (1) More likely to be red.