My Dad sent me a rather short email calling out my programming chops. See the following.

Screen_Shot_2014_01_19_at_10_30_54_PM

If I got this email from anyone else, I probably would have deleted it due to the spelling of “you’re” and my day would have been fine and dandy like cotton candy. But this being my father, I thought I would click on the link and see what he was talking about.

I’m assuming the puzzle has changed since I’m posting a solution but the puzzle listed was as follows

The problem itself didn’t seem so bad and I wanted to show my Dad that I’m an uber-hacker genius so I took a shot.

My first attempt went horribly wrong so I trashed it and started over. This code isn’t extremely fast but it gets the job done.

Running this program from the command line yields this.

So as you can see, this isn’t the fastest program in the world but it does yield a solution. On my 2010 Macbook Air it takes almost 1.8 seconds to get a result. If I get some time I may rewrite my solution again for some speed improvements.

Tagged on:

Leave a Reply

Your email address will not be published. Required fields are marked *