It’s Friday, and time again for a new Fragment: my weekly programming-related puzzle.
This Week’s Fragment
A recent Car Talk Puzzler challenged listeners to find two temperatures where the Celsius and Fahrenheit readings had the same two digits, but reversed. For example, 28 Celsius is 82 Fahrenheit. It’s an easy problem to solve by hand, but what fun is that? This is one where writing a bit of code will yield an answer faster than working it out by hand. Or, better still, offer a chance to try some new coding approaches. So, our programming version of this puzzle is:
Write code to find two (two-digit) temperatures where the (rounded) Celsius and Fahrenheit readings have the same digits, only reversed.
Use any language you’d like; you may want to try it in multiple languages to compare. You might even try an esoteric language like LOLCODE or Shakespeare.
If you want to “play along”, post the solution as a comment or send it via email. To avoid “spoilers”, simply don’t expand comments for this post. That is, unless you want to see what languages others used to deliberately try something different. Language wars can be such good sport.
Last Week’s Fragment – Solution
Last week’s fragment was one of those puzzles sometimes given as interview questions for programming and engineering jobs:
You have eight balls; seven weigh the same, but one is lighter than the others. Using a balance, how can you find the “oddball” in only two weighings?
Congratulations to Wayne who solved it swimmingly, and described the solution nicely:
Weigh three balls against another three balls. If they weigh the same, you simply weigh the other two to find the lighter one. If one set of three balls was lighter than the other though, weigh two of the balls in the lighter set of three against each other. If one is lighter, that’s it, else it’s the third one you didn’t weigh the second time.
I guess that means you’re hired!