Wednesday, August 6, 2008

Brain Den

So, you're at work and bored in front of the computer (duh! Why else would you be reading this?). Brainden.com is a place that I often wind up when I'm in this position. Please don't go there now, finish reading this post. Most of the time I just try to solve the puzzles in my head because people have already posted an answer. The thread that you see below was first solved by yours truly and the first puzzle that I solved first, btw. See what you can do with the puzzle before moving on to the website. I'll post the answer and the link to the post later (I want you to figure out the answer on your own). So here it is:

Most of today was spent in meetings with the PHB*, explaining why our project is behind schedule.

A quick virtual summary (what I imagine was said, rather than what was actually said): So anyway, it was a relief to get back to programming. As I dug into a bitmap edge detection algorithm, I ran into a spot where I needed to check the eight pixels surrounding the current one, in clockwise order, given any starting position. I whipped out a quick conditional statement that tested for each of eight possibilities, which works fine, but is ugly. Since it worked ok, I couldn't justify a lot of time to optimize it, so I gave myself five minutes to see if I could come up with a slicker way to do it. I didn't, so I moved on, but now it's 11PM and I just thought of another way to do it, and I figured it might be fun to see if anyone can find an even simpler solution.

So here's the problem ...

Consider the following diagram:



Find a single function f(x,y) that, given any one set of the eight coordinates, returns the coordinates of the adjacent square, moving clockwise. You may use any mathematical operands, including rounding, absolute value, trig functions, etc., but no conditionals.

*Pointy Haired Boss

No comments: