How can I pair socks from a pile efficiently?
stackoverflow.comBuy a dozen pairs all the same. Any two socks will match.
Otherwise, you have to sort them. I usually use the random sort method.
I take a sock from the pile. Does it match any sock previously taken? If so pair them and remove from the play. If not place that sock on its own in the 'previously taken' array. Repeat till all socks taken from the pile. Any socks taken but unmatched can be kept till next time or perhaps thrown in the rubbish bin.
This method is easier to do in practice than on a computer.