Algorithms For Efficiently Pairing Up Socks

Really, this could be the ultimate Lifehacker topic: is there an algorithm to more effectively sort a pile of socks into pairs?

Socks picture from Shutterstock

A discussion of approaches at Stack Overflow reviews several programmer-centric ways of tackling the issue, including this neat encapsulation of a basic approach in pseudo-code:

while (socks_left_on_a_surface()) {
// thanks to human visual SIMD, this is one, quick operation
pair = notice_any_matching_pair();

More nuanced approaches include roughly grouping socks of similar colours, then finding the matching ones, or using multiple people to sort the socks.

As with many programming problems, sometimes the most effective solution is to change the inputs. I'm one of those odd people who only ever buys socks in one style (plain black from Big W) -- that way every sock matches and there's no sorting required at all when you empty the laundry basket. Sadly, however, you still have to work out which ones are turned inside out.

How to pair socks from a pile efficiently? [Stack Overflow via Business Insider]


    I disrupt the paradigm by using Wizzpeg sock pegs. No sorting required - socks are always paired. In a multi-person household, using a different coloured sock peg for each person, is the only sane way to manage this problem.

    Last edited 30/04/14 9:55 am

    Just have two pairs of socks!
    One that you wash and the other pair you have on.
    Plus only buy socks that have an "L" and "R" on them. So you never pair the wrong
    sides if you have more pairs of socks.

    I posit that the time you spend finding the peg and applying it to the sock pairs when you take them off far outweighs the time taken sorting socks.

      Why? The pegs are stored next to the dirty clothes basket (or wherever the dirty socks are put when they are removed). In a multi-person household there can be over a hundred individual socks washed in a week - the time taken sorting socks is not trivial (or this used to be the case, until the deployment of the sock-pegs). The time taken to apply a peg is insignificant. Certainly over time there is a diminution in the number of sock pegs ... but the system is far more robust than I had originally anticipated and has worked well for many months now.

    I just buy a whole bunch of the same socks. Any two socks will match.

    Another wizzpeg sock household here! I have too many black pairs that are identical to do anything else.

    Somehow my dad ended up with all my black socks, so I bought ones with pretty patterns and coloured heels and now I never lose a pair.

    When I wash them, I pair them all up on the washing line and roll them up as I take them off.

Join the discussion!

Trending Stories Right Now