Intel's Ronler Acres Plant

Silicon Forest
If the type is too small, Ctrl+ is your friend

Sunday, October 3, 2010

Challenger Puzzle, Part 2

I wasn't real happy with the brute force solution I came up with earlier. I mean, it's a tiny little little puzzle, it shouldn't take hours to solve it with a computer. So I finally sat down and started working on a more workman-like solution. This one solves the puzzle instantly, or as near to no time at all that it makes no difference.

This program starts by filling all the unknown spaces with a median value (5) and then adjusting each one up or down by one depending on the totals it is concerned with. It took 8 iterations to solve the puzzle I was using as a sample, and I think it will probably not need any more for just about any Challenger puzzle.

It is not an elegant solution. It just sort of creeps up on the answer, it doesn't analyze the situation and then compute the answer in one fell swoop. If I start wandering down that road I hope somebody will stop me.

It did take several hours to debug the program. You would think something this small and simple would be a piece of cake, but for some reason keeping rows and columns straight is exceedingly difficult for me. But I finally got it done and posted it on another Code Snippets website. I am not sure whether it's the one for me, but I was able to sign up and post my code quite easily. Their focus seems to be on Mac's, but Mac's are related to Linux, so maybe they will be okay. Their code formatting sucks, as is typical. They use 8 spaces for tabs instead of four, and they chose some gawd-awful gold color for comments, which makes them durn near unreadable. It does not eat backslashes, like some other sites do. This is a good thing.

Anyway the name of the site is Snipplr and you can find the source code for my improved program for solving Challenger puzzles here.

No comments: