3 ms·
There seem to be a few different ways to use XOR on sequences of integers (or for exchanging the contents of two registers), and they're worth learning if you e
by raganwald 18y ago
There seem to be a few different ways to use XOR on sequences of integers (or for exchanging the contents of two registers), and they're worth learning if you ever need to go on a job interview with someone who uses "Aha!" style technical questions.
Beyond that, however, I'm left scratching my head. Just the other day zenspider and I were debating whether the k combinator is a useful tool for programming or whether it is "clever" code. Am I wrong in thinking that using XOR for finding an integer that only appears once is rather clever?
- kylec 18y agoYou are correct - the problem was probably constructed with that intended result. The specifications are unusually precise when it came to how the input was formatted. If they were any less precise XOR wouldn't work. ..a number that occurs only once in a list which has all other numbers occurring exactly twice..
- raganwald 18y agoI think somewhere in the "drafts" of blog posts that never made the light of day is one about "programming by isomorphisms." One of the greatest intellectual feats we have is to look at a problem and realize that it is isomorphic to some other solved problem. A lot of "Aha" programming challenges either test for the ability to recognize these isomorphisms (or more likely, they are culturally biased towards people with a lot of social exposure to older programmers). I suspect this kind of thing might be a test for a specific kind of intelligence. I do believe--in general--that all other things being equal, the smarter programmer is the best hire. But gosh, I admit to fearing this kind of actual code in production. It looks like exactly the kind of thing that breaks--possibly in subtle ways--when one of the underlying assumptions turns out to be false or is changed. Of course, changing assumptions are never part of the tests, so it might be "fair dinkum." So the follow-up question probably ought to be, "when would you actually use this device?"