# Red Marbles, Blue Marbles

Source: https://www.techinterview.org/post/526363745/red-marbles-blue-marbles/
Updated: 2026-04-16 · techinterview.org

Problem: you have two jars, 50 red marbles, 50 blue marbles. you need to place all the marbles into the jars such that when you blindly pick one marble out of one jar, you maximize the chances that it will be red. (when picking, you’ll first randomly pick a jar, and then randomly pick a marble out of that jar) you can arrange the marbles however you like, but each marble must be in a jar.

### Solution

Chance! chance is easy if you know how to do the formula. we know that we have two choices to make. first we’ll pick a jar, and each jar will have a 1/2 chance of being picked. then we’ll pick a marble, and depending how we stack the marbles, we’ll have a (# of red marbles in jar)/(# of total marbles in jar) chance of getting a red one.

for example, say we put all the red marbles into **jar A** and all the blue ones into **jar B**. then our chances for picking a red one are:

1/2 chance we pick **jar A** * 50/50 chance we pick a red marble

1/2 chance we pick **jar B** * 0/50 chance we pick a red marble

do the math and you get 1/2 chance for a red marble from **jar A** and a 0/2 chance for a red marble from **jar B**. add ‘em up and you get the result = 1/2 chance for picking a red marble.

think about it for awhile and see if you can figure out the right combination. we had a 50/50 (guaranteed) chance in picking a red marble from **jar A**, but we didn’t have to have 50 red marbles in there to guarantee those fantastic odds, did we? we could’ve just left 1 red marble in there and the odds are still 1/1. then we can take all those other marbles and throw them in **jar B** to help the odds out there.

let’s look at those chances:

1/2 we pick **jar A** * 1/1 we pick a red marble

1/2 we pick **jar B** * 49/99 we pick a red marble

do the math and add them up to get 1/2 + 49/198 = 148/198, which is almost 3/4.

we can prove these are the best odds in a somewhat non-formal way as follows. our goal is to maximize the odds of picking a red marble. therefore we can subdivide this goal into maximizing the odds of picking a red marble in **jar A** and maximizing the odds of picking a red marble in **jar B**. if we do that, then we will have achieved our goal. it is true that by placing more red marbles into a jar we will increase the chances of picking a red marble. it is also true that by reducing the number of blue marbles in a jar we will increase the odds also. we’ve maximized the odds in **jar A** since 1/1 is the maximum odds by reducing the number of blue marbles to 0 (the minimum). we’ve also maximized the number of red marbles in **jar B**. if we added any more red marbles to **jar B** we would have to take them out of **jar A** which reduce the odds there to 0 (very bad). if we took any more blue ones out of **jar B** we would have to put them in **jar A** which reduce the odds there by 50% (very bad).

it wasn’t really a good proof, but QED anyway :-P

## 2026 Update: Conditional Probability and the Marble Puzzle

The classic setup: one jar has 100 red marbles, another has 100 blue marbles. You must redistribute them between two jars, then pick a jar at random and draw a marble. How do you maximize the probability of drawing a red marble?

**Optimal strategy:** Put exactly 1 red marble in jar 1, and everything else (99 red + 100 blue) in jar 2. This maximizes P(red) ≈ 74.7%.


```
def marble_probability(jar1_red, jar1_blue, total_red=100, total_blue=100):
    """
    Given that we put jar1_red red and jar1_blue blue marbles in jar 1,
    compute P(drawing red marble) when we pick a random jar then a random marble.
    """
    jar2_red = total_red - jar1_red
    jar2_blue = total_blue - jar1_blue

    jar1_total = jar1_red + jar1_blue
    jar2_total = jar2_red + jar2_blue

    # P(red) = 0.5 * P(red|jar1) + 0.5 * P(red|jar2)
    p_red_jar1 = jar1_red / jar1_total if jar1_total > 0 else 0
    p_red_jar2 = jar2_red / jar2_total if jar2_total > 0 else 0

    return 0.5 * p_red_jar1 + 0.5 * p_red_jar2

# Brute force search for optimal strategy
best_p = 0
best_config = None
for r1 in range(1, 100):
    for b1 in range(0, 101):
        p = marble_probability(r1, b1)
        if p > best_p:
            best_p = p
            best_config = (r1, b1)

print(f"Optimal: {best_config[0]} red, {best_config[1]} blue in jar 1")
print(f"P(red) = {best_p:.4f}")  # (1, 0) → P = 0.5*1 + 0.5*(99/199) ≈ 0.7487
```

**Why (1 red, 0 blue) wins:** Jar 1 gives 100% red (guaranteed win half the time). Jar 2 gives 99/199 ≈ 49.7% red. Expected: 0.5 × 1.0 + 0.5 × 0.497 = 74.87%. This puzzle is about **extreme asymmetry** — a key mental model in probability optimization and system design (e.g., how to allocate resources to maximize a probabilistic outcome).
