Interactive visualizer for four classic interview problems.
A power of 2 has exactly one set bit. Subtracting 1 turns that bit off
and all lower zeros into ones, so x & (x - 1) becomes 0.
A left shift by 3 multiplies by 2³ = 8.
Therefore (x << 3) - x = 8x - x = 7x.
A sequence of fair coin flips creates a random binary number
U = 0.c₁c₂c₃…, uniform on [0,1).
Return True exactly when U < p, so:
P(U < p) = p
For a finite binary expansion, treat p as continuing with zeros forever. If all supplied bits tie, the result is False except for the probability-zero event of exact equality.
After 18 hours, dead mice represent 1-bits. Reading the pattern as a binary number identifies the poisoned bottle.
Each mouse gives one binary outcome: alive = 0, dead = 1.
2¹⁰ = 1024 unique patterns, enough for 1000 bottles.