DEV Community

Cover image for How many total sock inspections should be expected to perform?
Jeff
Jeff

Posted on • Edited on

How many total sock inspections should be expected to perform?

Farhad has just washed and dried all his socks at the laundromat. Now he wants to pair the socks up. (Each sock shares a unique design with its pair.)

Farhad starts with a total of 20 socks (10 pairs). He picks up and holds one sock in one hand. With the other hand, he picks up the other socks one-by-one until he finds the matching sock.

How many total sock inspections should Farhad expect he'll perform to finish pairing 20 socks?

The answer is 65.

The exact number of socks Farhad picsk up to pair his first sock depends on luck. On average, we'd expect him to pick up 11 socks to match his first pair. This estimate comes from averageing the lucky and unlucky numbers. That average is 20+22=11 \frac{20+2}{2}=11 if he has 20 socks.

Similarly, for the 2nd pair we'd expect him to pick up 18+22=10\frac{18+2}{2}=10 socks.

And so on, and finally 2 to match the last pair. This comes out to a total of sock 11+10+9+8+7+6+5+4+3+2=1011+22=513=6511+10+9+8+7+6+5+4+3+2=10\cdot\frac{11+2}{2}=5 \cdot 13=65 pick-ups.

Top comments (0)