Google prime number problem

Tuesday, December 19th, 2006

Few years ago google placed a bill board in Silicon Valley (Well, I haven’t seen that but read the googleblog post). The board was about a small programming problem.

Somehow, that blog post became one of the top stories in digg recently; after seen it, I decided to give it a try. I just used the straight forward brute force method and it was surprisingly easy. It was just like a old days doing an IOI code, and more to the point, runtime doesn’t matter, memory limits doesn’t matter, and coding time doesn’t matter, so, what make it an IOI code is that code quality also doesn’t matter.

I just code like I always did… just coded… coded… coded… never bothered about the coding standards… and finally two small programs (e.zip). First I generated factorials up to 100, divide 1 by all those and saved the result (upto 500 decimal places) in a file. Then from the next program I added all those things together and checked for a prime. Pretty simple. The answer was 7427466391

wget hack

Tuesday, December 19th, 2006

Today, I recursively downloaded a web site to my web server using wget, and for some reason it didn’t work well. Some of the immediate files are missing. After running through the original site source, I realized that it’s about the files inside the style sheets. So, I made some quick modifications to the wget source.

It’s just a hack to get my download working, however it will also work on some other sites as well(I hope ;-)). errr…. Sorry about the quality of code.

Unfortunately, I lost the original source code(I have no intention to download it again using my dialup; ah! I forgot to tell you, I’m enjoying the vacation at home; Ratnapura), so I can’t create patch files. wget version is 1.10.1. Download recur.c and html-url.c.