Let's say you have a cable that has n
wires. Each wire on the left side corresponds to one wire on the right side. However you cannot distinguish between the wires and you want to know which wire corresponds to another.
You can only use these three operations:
- Power on a wire on the left side
- Power off a wire on the left side
- Check if there is a power on a wire on the right side.
Try to minimize operations that are needed for you to distinguish all n
wires..
One straight forward solution would be:
- Power on a wire on the left side, check all
n
wires on the right to find matching one. - Power on another wire, now check
n - 1
wires on the right - ... Which would lead to n + (n - 1) + ... + 1 = $\frac{n*(n-1)}{2}$ operations to check wires on the right and $n-1$ operations to power on wires on the left. Resulting in $\frac{n*(n-1)}{2} + (n-1)$ operations
3!
. $\endgroup$