A Solution to Google Treasure Hunt 2008 Problem 4

Author: Simmoril | Date: 15.4.2009 | Category: General

From Google Treasure Hunt 2008:

Find the smallest number that can be expressed as
the sum of 3 consecutive prime numbers,
the sum of 5 consecutive prime numbers,
the sum of 517 consecutive prime numbers,
the sum of 551 consecutive prime numbers,
and is itself a prime number.

For example, 41 is the smallest prime number that can be expressed as
the sum of 3 consecutive primes (11 + 13 + 17 = 41) and
the sum of 6 consecutive primes (2 + 3 + 5 + 7 + 11 + 13 = 41).

I wrote my solution to this problem in ~60 lines of python. In a nutshell:

1. Get a precomputed list of (1,000,000) primes.

2. Find all possible summations of 551 consecutive prime numbers. If the sum is prime, store this in a list of ‘candidates’.

3. Find all possible summations of 517 consecutive prime numbers. If the sum is in the candidate list from step 2, store it in a new candidate list.

4. Repeat step 3 using this new candidate list for summations of 5 and 3 consecutive prime numbers.

5. The smallest number in the final candidates list is the answer.

The script ran pretty quickly on my machine (3.00 GHz P4), taking about 1-2 minutes to find the answer.

Book Review: The Productive Programmer

Author: Simmoril | Date: 9.9.2008 | Category: General

The Productive ProgrammerHonestly, I have to say I was surprised to see that (at the time of this writing) this book was averaging 4.5 stars on Amazon. I suppose my expectations of this book were heavily swayed by the title. I was expecting something a little more generic and high-level than what I got.

I think the book makes a decent attempt to provide the reader with ‘recipes’ that can be used to improve their efficiency and productivity. But the recipes themselves seem to be a little too free-flowing: by the time I got around to the 3rd or 4th recipe, I had already forgotten the overarching theme of the chapter. I feel like the material might’ve been better presented in the style of O’Reilly’s “Cookbook” book. I doubt a reader, after one pass through the book, will be able to implement every recipe they read about. I think it would be better to structure the book as a reference that they can flip through later.

Another issue I had with the book was that in the later half of the book, many of the examples given contain chunks (sometimes large chunks) of Java, Ruby, and Groovy code. While I’m sure many readers of this book are familiar with those languages, for those who aren’t, the chunks become a serious roadblock to understanding the point of the example. Many of the examples (the Groovy ones, especially) cannot simply be interpreted ‘by sight’. Perhaps a future edition of the book could have some type of fair warning at the beginning.

If you are a java developer, I think you can probably get a lot out of this book. If not, you’ll probably still be able to get a good amount of information out of the first few chapters, but I’d suggest just skimming or skipping the latter chapters altogether.

My rating: 3/5 stars.

Book Review: Programmer’s Guide to nCurses

Author: Simmoril | Date: 28.8.2008 | Category: General

Programmer\'s Guide to NCursesA couple weeks ago, I wanted to start playing around with the python curses module, but it’s been almost forever since I’ve done anything with curses. So, for a bit of a refresher course, I picked up Dan Gookin’s Programmer’s Guide to nCurses (note this book covers the C API, not the python API).

I was actually very surprised at how good of an introduction Dan’s book is. His laid back style of writing helps keep the reader entertained, and his short code snippets make for succinct examples that get right to the point without losing the reader in pages of boilerplate. The book itself is a fairly quick read too; although it officially weighs in at 556 pages, the last 300 pages or so is a reference manual for the nCurses API.

I honestly didn’t have too many problems with the book, other than the occasional typo (including an off-by-one error in the code on p. 177). However, I would warn the reader that I had some issues with a few of Dan’s examples. First, in many of the examples, the error handlers are missing a getch() call, which causes the program to immediately exit when an error occurs without pausing to let you see the errors. Also, in Chapter 8, some of the examples involving wrefresh() wouldn’t work for me unless a call was made to refresh() beforehand (but after that call was made once, all the wrefresh() calls worked after that). Not sure if this is an issue with nCurses or with my system, so YMMV.

I would definitely recommend this book to anyone who is looking to become familiar with the nCurses API. Although the book doesn’t cover more advanced topics, like best practices for designing and building full-fledged nCurses applications, it still makes for a very good starting point.

My Rating: 4/5 stars.

A Solution to the WordNumbers Puzzle

Author: Simmoril | Date: 27.7.2008 | Category: General

Well, it’s been a long time coming, but I finally finished my write-up of the solution to the WordNumbers puzzle.

The WordNumbers puzzle is one of a series of programming challenges posed by ITA Software as part of their hiring process. When I saw the WordNumbers puzzle, the description was so simple, yet when I first started to work on it, I honestly had no idea where to start. But, a couple days, and a couple of key insights later, and I was able to code up a program that yielded the correct answer. However, it turned out that writing a paper describing the solution took a lot longer than writing the actual solution itself!

I’ve omitted my implementation of the solution as well as the actual answer because I don’t want to spoil the puzzle for anyone else. But, for those of you who are dying to know the answer, I hope that my paper points you in the right direction towards implementing the solution on your own.

As always, I welcome any questions, comments or criticisms you may have. If you see any glaring errors and/or omissions, please let me know. It’s been quite a while since I’ve had to write a paper, and this was a tough subject to write on, so please, be kind!

Still Alive

Author: Simmoril | Date: 15.7.2008 | Category: General

Wow, been quite awhile since I’ve posted here. Yes, I’m still alive, just caught in a bit of a whirlwind right now, so I’ll have to make this short.

First off, I’m heading to Vegas in a couple of days for a meeting that I’m stressing out big time over. I’ll write about it more when I get back, right now, I just need all the time I can get to prep.

Second, I’ve decided to give Twitter a  try, so I’ve added a link to my Twitter page on the sidebar. It seems to be the in thing, so I figured I’d jump on the bandwagon.

Third, I’ve got a writeup in the pipeline that I’ll post here once it’s finished. I hope by mentioning it here, it’ll motivate me to actually get it done.

See you when I get back from Vegas.

Live Free or Die Hard Sucked

Author: Simmoril | Date: 23.2.2008 | Category: General

Full disclosure: I got about 53 minutes into this movie before I had to shut it off. Part of that had to do with me seeing it get a 7.7 rating from IMDB.com, who, btw, I have now lost all respect for. Seriously, anyone who thinks that this movie has a plausible plot line with a credible threat needs to be banned from ever using technology ever again.

Book Review: Way of the Peaceful Warrior

Author: Simmoril | Date: 28.1.2008 | Category: General

Way of the Peaceful Warrior Book Cover

I must admit, as I was reading this book, I radically changed my mind about what I wanted to write in this review. I went though a veritable roller-coaster of emotions; I hated it, I liked it, I loved it. By the end, I could almost guarantee that anyone reading this book will have a strong opinion on it.

I know that this book finds it’s way into the ’self-help’ section of many bookstores, but I really hesitate to place it in that category, as it’s not a how-to; the book doesn’t explicitly state “do this and you will feel better”, but rather it presents the reader with a narration of the author’s life, after which it is up to the reader to decide what they want to take away from it.

Dan’s recount of his tales was really captivating. As I was reading it, I felt myself really associating with him and understanding the feelings he went through in his time with Socrates. At various points in the book, Millman recounts these short tales that almost read like fables. I would often stop and just try to extrapolate the morals behind these tales before going on to read what Millman had to say about them.

Probably one of the most impressive things about this book is its emphasis on the value of hard work. Millman doesn’t just experience a single event with Socrates: he embarks on a journey, a process that takes a great deal of time and effort to help transform him, to help him learn. At the beginning of the book, I had this great fear that the book would present Socrates as this ’silver bullet’, this one magical fix for Dan’s life, and so I was really pleased to see that that wasn’t the case.

Although I truly appreciate the message that Millman was trying to get across with his book, I have to admit that there were some things about it that put me off. First off, Millman’s ‘embellishments’ in his story-telling were too much to take at times. While they may spice up the plot, I think it clouds some of the points the book is trying to get across. Reality is reality, fantasy is fantasy, and with a subject like this, getting the two confused can be dangerous.

Another sticking point with me were some of the values that Socrates deemed unimportant and those he deemed invaluable. The care-free attitude that he and his friend Joseph embodied may work for them, but it forgets the responsibility that many people in this world have. A key example of this is parents: if their children make them unhappy, they can’t just up and leave them. If they don’t like their job, they can’t just quit it if they don’t have another one.

At one point in the book, Socrates made a comment criticizing moderation, saying that it was only something for the bland, apologetic, and fence-sitters of the world. I feel Socrates is making a mistake here by confusing moderation with indecision. I don’t think there’s anything inherently wrong or harmful with being patient and making good, calculated decisions instead of foolish, impulsive ones.

I do honestly believe this is a good work by Millman, and one that just about everyone reading it can get something out of. However, I would encourage people to take it with a grain of salt, and to really decide for themselves whether or not what they got out of the book applies to their own life.