"The poet only asks to get his head into the heavens. It is the logician who seeks to get the heavens into his head. And it is his head that splits." G.K. Chesterton

Sunday, April 25, 2010

{First 10 digit prime in consecutive digits of e}.com

I recently watched a documentary about Google Inc., its beginnings and style of doing business. There was an interesting fact about a recruiting campaign which they launched some years ago. It involved billboards containing a cryptic, and mysterious message: {First 10 digit prime in consecutive digits of e}.com. Finding that prime, and going to the page named after it would take one to a Google jobs page with congratulations of completing stage 1 in the recruiting procedure. Consequently one would be presented with another puzzle to pass further stages. I think that is an avantgarde and clever way of attracting all the IT nerds out there.


Being a bit of a nerd myself, I found the problem itself quite interesting, and since it didn't seem that difficult at first glance, I eventually solved it. The only tricky bit was getting my hands on the 10 digit primes set. Anyway, my approach was to write an algorithm in MATLAB to get the answer.
Directly below is the main function, and further below are some auxiliary functions used in the main one.  
Click on the images to enlarge.


The one below is self explanatory: parity check function.


The one below proved very helpful in the main code, since it allowed to perform arithmetic between vectors (digits of e) and scalars (primes). It converts a 1D array into a scalar (well actually into a string consisting of the original array entries), for any integer array. It does not actually convert it into scalar (consider an array with 0 in the first column), but the sieve in the main code skips all such cases.
 And upon execution ... BINGO!



2 comments:

Zegarnek said...

Please explain, plese.

What are vectors doing in mathematics of prime numbers?

Mariusz Popieluch said...

They're not used here in the "mathematics of prime numbers" as you put it, but in the algorithm used to match scalars (primes in this case) with vectors i.e. 1 dimensional array elements.

I converted the consecutive digits of e: 2.7182818... into consecutive entries of a vector e: [2,7,1,8,2,8,1,8,...]. This way the algorithm can compare whether those entries match some prime i.e. the first 10 digit one.