How to pair socks from a pile efficiently?
stackoverflow.com
stackoverflow.com
When most of them have at least one hole I recycle them and start over.
For reference, these are good socks in my book: http://www.happysocks.com/uk/combed-cotton-polka-stripe-14.h...
The advantage of having such socks is that, since I normally only wear black, it make me seem slightly less boring. The disadvantage is that it's hard to find really worthwhile socks. The secrets of the trade are:
1. Always be alert. If you pass by a sock shop, go in. I once did it on a first date.
2. If you see socks you like, buy them. Don't say "I'll come back later" or "I'll find them online". You'll soon realise it's a buy-now-or-get-heartbroken affair.
3.the Internet is your friend. Compile a list of brands who are more likely to produce good socks and online shops who sell them.
3.5 Pro tip: Swedish brands are very colourful-sock friendly.
4. Visit those online shops regularly to see if they have anything worth buying.
5. You can never have enough socks, so if you see qualifying socks, buy them. You can always store them and use them at a later date.
6. Never buy more than one pair of the same design. The only exception is if there is a pair you see you exceptionally like, in which case you can buy two pairs, but store one pair to when the first pair is too worn out to wear.
Edit: formatting.
Edit 2: this obviously also solves the problem of having to throw good socks out as their general population get worn out.
I don't have a formal rotation system, though. Just drawing at random from the drawer seems to produce approximately equal wear.
Of course I also own few other colors for special occasions and sport socks, they go to separate drawer.
I'd agree khaki pants with brown shoes would be weird with black socks
If you don't care about fashion, it doesn't matter, though
I fairly quickly moved to an algorithm that I would later learn was MSB radix-sort. Basically, I made one iteration and divided them into buckets with the same value in the "hundreds" column, and then recurse into each pile and repeat for the "tens" column, then a quick sort for the final 10 orders.
As a concrete example, lets say I had 150 orders with order numbers between 7200 and 7499. Organize into piles containing the 7200s, the 7300s and the 7400s. Then take the 7200s, and split it into piles for 7200s, 7210s, 7220s, etc.
In sorting algorithms, it common to use insertion sort for the final step (actually, people often use any O(N^2) sort, but really should only ever use insertion sort because its the most efficient O(N^2) sort in terms of instruction count, cache locality, and branch mispredictions).
You could construct situations where it would be faster to switch to insertion sort (maybe radix of 2, stop 3 recursions from the end), but in practice you'd pick a radix better (with a radix of 8, you could do the entire thing in 4 recursions and the final recursion over 64 items is faster than insertion sort of 64 items, probably).
Note that you'd generally use LSB radixsort over MSB radixsort, so you'd have a set number of passes over the array, and no recursion.
Here's code for an LSB radix sort, which doesn't recurse, but is the same idea: https://github.com/pbiggar/sorting-branches-caching/blob/mas...
If you find a way to not jumble the socks as you fish around, you will be able to remember their locations. (up to a certain number)
The human brain is very parallel in it's image recognition, if your socks look different enough just placing your gaze in the general vicinity will lead to a match.
As you find pairs, the stack size gets smaller. (making the above two effects increase their strength)
Some socks will have multiple valid 'buddy' socks. (think a pack of identical socks... each sock will match any other)
So, version one: - Spread your socks out all over the floor/table - Pick up a sock that appears to be the most common. (you can optimize this later by memorizing the 5 or so types of socks you have the most of) - Find a matching sock, return to step two.
Hopefully, this will allow the decreasing pile size to counteract the depletion of easily-matched socks, keeping the whole thing under your brain's limits for parallel sock matching.
(I'm posting this here because I'd like some peer review before I make my answer final.)
I have an O(1) solution that is fairly reliable for matching a single pair. Pick out a sock from the drawer. Then go find your kids; they ran off with the matching one when you weren't looking (requires that you live with at least one young child).
step 1) discard all your existing socks
step 2) go to walmart and buy them by packets of 10 - n packet of white and m packets of black. No need for other colors in everyday's life.
Yet times to times I have to do this again (lost socks, damaged socks etc.) and I hate to discard perfectly good socks too often (and I wished they kept selling the same socks reference!) so I recently took a different approach.
Consider than if you draw only 1 sock for the 2n stack of socks, your odds of finding the matching sock in a naive search is quite low.
Pick up 5 of them at random (usually humans are good are remembering between 4 and 7 different elements in the working memory - a bit like the human equivalent of a RPN stack - 5 is a safe default) and memorize their shape or their length.
Pick up one from the stack of 2n-5.
Now look for a match (visual pattern matching - humans are good at that with a small stack) inside the 5 you drew, if you don't find one, then add that to your 5 and keep randomly picking socks from the stack and compare to your 5+1 socks for a match (it will reduce your performances but raise your odds)
Much faster. Feel free to write down the formula (it's late, I'm getting sleepy) to calculate how much samples you have to draw for a 50% odds of a match. IIRC it's an hypergeometric law.
I do that every morning and rarely need more than 3 draws. Now you can estimate the size of my stack of stocks :-)
BTW I found that the transaction costs of sorting all the socks every time I needed a pair were far less than doing it once and binding the socks - because then you don't have to bind the socks, and there's also a diminishing marginal return (ie you keep looking for that 2 or 3 socks that when somewhere in the laundry and that you need to finish matching your socks and you lose time on that)
When a sock is lost, discard it's peer. When the pair is replaced, reuse the id. This keeps the ids dense.
After doing the laundry, you can place each sock based on its id, and match up everything in O(n).
Washing them paired up (one rolled inside the other) is even better, O(n), where n is the number of pairs, not the number of socks. But I don't think the socks get really clean.
RFID tags and, uh, a robot thing.
This can be done two ways:
Either have only one color.
The other option is to make it your thing to have odd pairs. Works better the more different from each other they are.
http://www.blacksocks.com/en-us/smartersocks_simplyexplained...
I use those practical laundry sock clips. Sock pairing:
O(1). Problem avoided. ;-) – Tomalak 12 hours ago2>Buy identical socks.
3>Stop worrying about it.