Project Euler 7

My old online journal kept track of my progress through the Project Euler problems. I’m glad I kept track of them there (by posting the source) because the first 12 problems I solved were individual programs scattered across three computers (and one virtual machine).

At the start of the year I decided to organize all of the individual programs into one big program, and to that end learned Git and made a GitHub account. The first version simply ran every problem in sequence, and the second version used a command line argument that drove a switch statement to run the appropriate solution. This was functional for running individual solutions, but wouldn’t have been graceful to run all the projects in sequence (without having one switch case that listed every single function for the solutions – not too bad at around a dozen solved problems, but would have been unsightly after a dozen more).

Through the power of GitHub’s collaborative features, my buddy Matt jumped in and implemented a jump table so that we could address each solution by using the problem number as the index. Running all of the problems is as easy as looping through all the available indexes (which we manually keep track of). He also added a way to check answers, and if necessary print debug information. The only downside is that adding a solution requires touching a few headers to update how many problems are solved, add a function to the function pointer table, and add the solution to the solution array. I invariably forget to do one of these on the first try.

Up until yesterday I had implemented solutions for problems 1 through 6, and problem 8. My solutions to problems 7, and 9 through 13 are still scattered around various computers.

Last night I found my solution to problem 7. When I wrote it I created a user interface for it with GTK+ (since I was also learning that at the time), but my overall design was not very elegant and the solution code was intermixed with GUI code. Since I took a long nap on Sunday I stayed up a bit and re-wrote it more or less from scratch. It’s a simple problem so it didn’t take long.

To stretch myself a bit I wrote the solution up using Emacs on my laptop, then copied it to my Linux box using scp and put a few finishing touches on it over ssh. Why Emacs over VIM? Because Emacs had better syntax highlighting without having to mess with configuration files. Now that I have a few basic commands memorized I’ll probably stick with it. I COULD have just cloned the Git repository and done everything from the laptop, but I wouldn’t have learned anything new.

Real life is getting in the way of studying programming, so I’m glad I have something to show for a few late night hours.

This entry was posted in Hobbies, Programming. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s