Live data from Hacker News

How to pair socks from a pile efficiently?

stackoverflow.com

11–20 of 42 posts

Re: How to pair socks from a pile efficiently?

#11
No one owns enough socks of enough different kinds to make the accepted solution the most efficient.

It's much easier to simply try for a match on an unmatched sock, and if there is no match put that sock into cache (usually somewhere else on the bed). Your cache will probably never get above about 8 socks without a match.

Re: How to pair socks from a pile efficiently?

#13
post #6

The first answer is kind of labourous, isn't? I thought about simply removing a sock from the pile and isolating it. One for one, maybe puting the man's socks on the left and the women's on the right. So everytime you grab a new sock you can quickly check if you already isolated the pair of that one. This way you just have to grab each sock once. (this is similar to the second answer, but no need to prepare a flat pi…

Yup. Unless you have millions of socks, you can afford to "hash" each style sock by color + pattern + size + whatever, rather than repeatedly into ever-smaller piles based on just one of the metrics.

That's actually how I pair my socks from the laundry pile, anything else seems kind of silly...

This kind of recursive hash partitioning is actually being done by SQL Server when it needs to hash join or hash aggregate over huge data sets.

My pile of socks is not a huge dataset. They easily fit on the seat of my couch when laid out in pairs.

Re: How to pair socks from a pile efficiently?

#14
post #5
post #2

The real world meets the world of algorithms. I solve the issue by buying only 1 color and type of sock.

Exactly. O(1) FTW!

well considering that the number of socks is limited by the number of atoms in the universe, we can make pretty much any time-bound algorithm O(1)

Re: How to pair socks from a pile efficiently?

#15
post #9
post #8

I have 18 pairs of the same sock. I found that the most efficient way. YMMV.

Isn't this making it especially more complex because now you have to match based on wear, not just the pattern? With different patterns it's easier as the wear is constant for each pair. OCD mileage may vary :)

I upvoted because you make an interesting point, but I'm surprised to hear anybody matches socks that carefully!

Also, wouldn't the wear work out to be roughly equal if you alternate socks roughly equally?

Re: How to pair socks from a pile efficiently?

#16
post #9
post #8

I have 18 pairs of the same sock. I found that the most efficient way. YMMV.

Isn't this making it especially more complex because now you have to match based on wear, not just the pattern? With different patterns it's easier as the wear is constant for each pair. OCD mileage may vary :)

Interesting, hadn't thought about it that way. Definitely bugs me when I wear two socks of the same color/brand/etc. that fit differently due to age.

Re: How to pair socks from a pile efficiently?

#17
post #9
post #8

I have 18 pairs of the same sock. I found that the most efficient way. YMMV.

Isn't this making it especially more complex because now you have to match based on wear, not just the pattern? With different patterns it's easier as the wear is constant for each pair. OCD mileage may vary :)

I do pretty much the same thing (although I have two colours :) Since you don't ever pair any of your socks the wear is fairly even since you are picking two random socks every morning. If a single sock gets a hole in it you just throw it out!

Re: How to pair socks from a pile efficiently?

#19
post #9

Earlier quoted context omitted.

Isn't this making it especially more complex because now you have to match based on wear, not just the pattern? With different patterns it's easier as the wear is constant for each pair. OCD mileage may vary :)

I upvoted because you make an interesting point, but I'm surprised to hear anybody matches socks that carefully! Also, wouldn't the wear work out to be roughly equal if you alternate socks roughly equally?

> Also, wouldn't the wear work out to be roughly equal if you alternate socks roughly equally?

My guess is that this is a poisson process, so there would be a tail of (a few) socks which are randomly worn more than others?

Re: How to pair socks from a pile efficiently?

#20
post #2

The real world meets the world of algorithms. I solve the issue by buying only 1 color and type of sock.

What happens when your brand/model is discontinued?

I had this happen a few years ago, though in a slightly different fashion. The same "model" of sock was around, but the design changed once (width of stripes) and the material/construction quality changed several times. So despite having had ~15 pairs of the "same" socks, I still had to match because otherwise they would feel different on my feet. That's obviously not an issue in the grand scheme of things, but it bothered me :)
Post reply on HN