This one is new to me. Well played, Google.
This is a good, basic logic problem. The solution is in the comments at this post for those (like me) who are a little rusty at this.
Rob Pike posted this on Google Plus a few days ago here and I had to share it.
A few years ago I saw this page: http://www.csis.pace.edu/~bergin/patterns/ppoop.html
Local discussion focused on figuring out whether this was a joke or not. For a while, we felt it had to be even though we knew it wasn’t. Today I’m willing to admit the authors believe what is written there. They are sincere.
But… I’d call myself a hacker, at least in their terminology, yet my solution isn’t there. Just search a small table! No objects required. Trivial design, easy to extend, and cleaner than anything they present. Their “hacker solution” is clumsy and verbose. Everything else on this page seems either crazy or willfully obtuse. The lesson drawn at the end feels like misguided epistemology, not technological insight.
It has become clear that OO zealots are afraid of data. They prefer statements or constructors to initialized tables. They won’t write table-driven tests. Why is this? What mindset makes a multilevel type hierarchy with layered abstractions better than searching a three-line table? I once heard someone say he felt his job was to remove all while loops from everyone’s code, replacing them with object stuff. Wat?
But there’s good news. The era of hierarchy-driven, keyword-heavy, colored-ribbons-in-your-textook orthodoxy seems past its peak. More people are talking about composition being a better design principle than inheritance. And there are even some willing to point at the naked emperor; see http://prog21.dadgum.com/156.html for example. There are others. Or perhaps it’s just that the old guard is reasserting itself.
Object-oriented programming, whose essence is nothing more than programming using data with associated behaviors, is a powerful idea. It truly is. But it’s not always the best idea. And it is not well served by the epistemology heaped upon it.
Sometimes data is just data and functions are just functions.
This is fascinating, so much so that I just did a bit of research to verify that this wasn’t just made up. It’s true all right. It tells us just how metaphorically – and not literally – the Bible was written.
This video is exactly right.
Tyson makes a perfect case for why we need to change the way we educate in the US. STEM is critical in teaching people how to solve problems and provides the broad understanding and mental capacity required to create, innovate, and advance a team, a company, a nation, and over time the world. STEM is a primary engine of progress.
Tyson, in this short interview, has given yet another talk that no one should miss, no matter who they are. We as a species are approaching a state in which understanding the idea in this short video can determine our long term survival.
The discovery of a winning strategy for The Prisoner’s Dilemma has many of this working in game theory re-examining longstanding assumptions. I won’t say more as it’s best just to read the article.
Wikipedia has a List of lists of lists page. I wasn’t sure if I could love Wikipedia more than I did before learning that, but if I could, then I did, and I do.
I just want to call attention to an often overlooked little 1884 novel called Flatland, which describes a society of two dimensional figures, with the angular and linear characteristics of each serving to relegate him or her to a particular social class. There’s much more that happens in this book and it’s an interesting read, both as an introduction to thinking of objects as having properties according to their dimensionality and for the insight it gives into the rigid class structure of the Victorian society the author lived in and describes in the book.
Recent Article on Flatland – http://www.americanscientist.org/bookshelf/pub/a-forgivably-flat-classic
Flatland at Amazon.com – http://www.amazon.com/Flatland-Romance-Dimensions-Thrift-Editions/dp/048627263X
Check out this math problem I found on the xkcd blog:
Alice secretly picks two different real numbers by an unknown process and puts them in two (abstract) envelopes. Bob chooses one of the two envelopes randomly (with a fair coin toss), and shows you the number in that envelope. You must now guess whether the number in the other, closed envelope is larger or smaller than the one you’ve seen. Is there a strategy which gives you a better than 50% chance of guessing correctly, no matter what procedure Alice used to pick her numbers?
HINT: I’ll give a slight hint in that if you consider the range of the real numbers, it should make the answer clearer. Hopefully that didn’t give it away.