How to efficiently sort socks  JAN 22 2013

From Stack Overflow, a question about how to efficient sort a pile of socks.

Yesterday I was pairing the socks from the clean laundry, and figured out the way I was doing it is not very efficient. I was doing a naive search -- picking one sock and "iterating" the pile in order to find its pair. This requires iterating over n/2 * n/4 = n^2/8 socks on average.

As a computer scientist I was thinking what I could do? sorting (according to size/color/...) of course came into mind to achieve O(NlogN) solution.

And everyone gets it wrong. The correct answer is actually:

1) Throw all your socks out.

2) Go to Uniqlo and buy 15 identical pairs of black socks.

3) When you want to wear socks, pick any two out of the drawer.

4) When you notice your socks are wearing out, goto step 1.

QED

Read more posts on kottke.org about:
fashion   how to   programming

kottke.org

Front page
About + contact
Site archives

Subscribe

Follow kottke.org on Twitter

Follow kottke.org on Tumblr

Like kottke.org on Facebook

Subscribe to the RSS feed

Advertisement

Ads by The Deck

Support kottke.org shop at Amazon

And more at Amazon.com

Looking for work?

More at We Work Remotely

Kottke @ Quarterly

Subscribe to Quarterly and get a real-life mailing from Jason every three months.

 

Enginehosting

Hosting provided EngineHosting