…snow overnight and then freezing rain…
…snow overnight and then freezing rain…
This is a long one, but worth 13 minutes of your life.
(What else are you going to do, anyway? Watch Celebrity Come Dancing?/Got Talent?/X Factor?)
…”What is Time magazine for?” he’d probably talk about setting society’s agenda, capturing the attention of the educated and powerful and most of all, delivering the best weekly news package he could.
Today, the answer is clear. The purpose of the magazine is to make as much money as possible. Everything else is in service of that goal.
The rest of a very good article is here on Seth Godin’s website
From Jason Kottke’s kottke.org
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 = n2/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 an O(NlogN) solution.
Hashing or other not-in-place solutions are not an option, because I am not able to duplicate my socks (though it could be nice if I could).
So, the question is basically:
Given a pile of n pairs of socks, containing 2n elements (assume each sock has exactly one matching pair), what is the best way to pair them up efficiently with up to logarithmic extra space? (I believe I can remember that amount of info if needed.)
I will appreciate an answer that addresses the following aspects:
One option:
Suppose that you know that your 2n socks are arranged this way:
p1 p2 p3 … pn pf(1) pf(2) … pf(n)
where f is an unknown permutation of the set {1,2,…,n}. Knowing this cannot make the problem harder. There are n! possible outputs (matchings between first and second half), which means you need log(n!) = Omega(n log n) comparisons. This is obtainable by sorting.
Since you are interested in connections to element distinctness problem: proving the Omega(n log n) bound for element distinctness is harder, because the output is binary yes/no. Here, the output has to be a matching and the number of possible outputs suffices to get a decent bound. However, there’s a variant connected to element distinctness. Suppose you are given 2n socks and wonder if they can be uniquely paired. You can get a reduction from ED by sending (a1, a2, …, an) to (a1, a1, a2, a2, …, an, an). (Parenthetically, the proof of hardness of ED is very interesting, via topology.)
I think that there should be an Omega(n2) bound for the original problem if you allow equality tests only. My intuition is: Consider a graph where you add an edge after a test, and argue that if the graph is not dense the output is not uniquely determined.
Another option
List<Sock> UnSearchedSocks = getAllSocks();
List<Sock> UnMatchedSocks = new list<Sock>();
List<PairOfSocks> PairedSocks = new list<PairOfSocks>();
foreach (Sock newSock in UnsearchedSocks)
{
Sock MatchedSock = null;
foreach(Sock UnmatchedSock in UnmatchedSocks)
{
if (UnmatchedSock.isPairOf(newSock))
{
MatchedSock = UnmatchedSock;
break;
}
}
if (MatchSock != null)
{
PairedSocks.Add(new PairOfSocks(MatchSock, NewSock));
UnmatchedSocks.remove(MatchedSock);
}
else
{
UnmatchedSocks.Add(NewSock);
}
}
The right answer
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.
Can You Be A One-Woman Man – Sam Dees – The Chess Story 1947-1975 (1969-1975) [Listen]
Can’t Repeat – The Offspring – Greatest Hits [Listen]
Diaraby Magni – Vieux Farka Toure – Fondo [Listen]
Generator – Gap Dream – BIRP! October 2012 [Listen]
Here Comes Santa Claus – Bob B. Soxx & The Blue Jeans – A Christmas Gift for You From Phil Spector [Listen]
My Buddy – Dr. John – Trippin’ Live [Listen]
Poor Old Dirt Farmer – Levon Helm – Dirt Farmer [Listen]
Wild Situation – Dennis Wilson – Pacific Ocean Blue [Listen]
You Can Call Me Al (Paul Simon cover) – Noah & The Whale – Miscellaneous Covers [Listen]
You See Me – The Band – Jubilation [Listen]
Billy Preston, Dr. John, Joe Walsh, Levon Helm, Rick Danko, Garth Hudson, Nils Lofgren and Clarence Clemons
Oh, and Ringo, too.
The All Starr Band, 1989
Someone wrote: “There’s a fine line between genius and insanity and I believe Keith erased it some time ago….”
You must be logged in to post a comment.