Chapter 39
Can You Get A Haircut Already?
The Riddler for February 28, 2020. The Express is a dark-room card trick: split a deck into two piles with equally many face-up cards, blind. The Classic is a queueing problem at a barbershop where you hold out for one particular barber.
Riddler Express
You sit in a dark room at a table with a single pile of cards, exactly of them face up and the rest face down. You can feel and move the cards but cannot tell by touch which way any card faces. How can you make two piles (each with at least one card) guaranteed to hold the same number of face-up cards?
The Riddler, FiveThirtyEight, February 28, 2020(original post)
Solution
The one number you know is that cards face up. So separate exactly cards into a new pile, and flip that whole pile over.
Here is why it works. Say the cards you moved happen to contain face-up cards. Then the other cards hold the remaining face-up cards. Flipping the -card pile turns its face-up cards face down and its face-down cards face up, so that pile now shows face up, exactly matching the big pile. The two piles agree no matter what was:
You never needed to know which cards were which, only that faced up to begin with. Splitting off cards and flipping them works whenever equals the known face-up count.
The computation
Encode the trick: shuffle a deck of face-up and face-down cards, peel off any , flip them, and check both piles match every time.
import random
rng = random.Random(0)
ok = True
for _ in range(1_000_000):
deck = [1]*13 + [0]*39 # 1 = face up
rng.shuffle(deck)
pile, rest = deck[:13], deck[13:]
flipped = [1 - c for c in pile] # flip the 13-card pile
if sum(flipped) != sum(rest):
ok = False; break
print(ok) # True
Across a million shuffles the flipped pile always matches the rest, as boxed.
Riddler Classic
At a barbershop, four barbers work at once and every haircut takes exactly minutes. You only want the owner, Tiffany: if another chair opens and it is your turn, you wave it on to the person behind you and keep your place at the front of the line. A quarter of the other customers also hold out for Tiffany; nobody holds out for the other three barbers. You arrive to find all four barbers busy (you know nothing about how far along each cut is) and exactly one customer waiting ahead of you. What is your expected wait for a haircut from Tiffany?
The Riddler, FiveThirtyEight, February 28, 2020(original post)
Solution
Since you arrive at a random moment, Tiffany’s remaining time and the other three barbers’ remaining times are each uniform on and independent. The one customer ahead of you holds out for Tiffany with probability .
If the customer ahead holds out for Tiffany (probability ): they are ahead of you in her queue, so you wait for her current cut to finish and then for theirs, .
If the customer ahead does not hold out (probability ): they grab the first chair to open. If a non-Tiffany barber opens first, they take it and you slide into Tiffany’s chair when she finishes, . But if Tiffany opens first, the customer ahead takes her, and you wait for her next slot, . The extra appears exactly when is the smallest of , which by symmetry happens with probability . So
Combining the two cases,
The computation
Simulate your arrival: draw four uniform remaining times and a hold-out coin for the customer ahead, apply the waiting rule, and average.
import numpy as np
rng = np.random.default_rng(0)
runs = 4_000_000; total = 0.0
for _ in range(runs):
t, b1, b2, b3 = rng.uniform(0, 15, 4)
if rng.random() < 0.25: # ahead holds out for Tiffany
wait = 15 + t
else:
wait = 15 + t if t < min(b1, b2, b3) else t
total += wait
print(total / runs) # ~14.0625