Speaking of Google Puzzles

I mentioned a similar puzzle that google has poised in the form of a roadside advertisement. The board says:

{first 10-digit prime found in consecutive digits e}.com

The first step to sovling this part of the problem is to obtain a list of prime numbers and some digits of e. You can obtain digits of e almost trivially on the Internet using Google. Obtaining a list of ten digit prime numbers can be found two ways. If you really wanted to brute force the issue you could subset every set of 10 digit numbers in the digits of e and then check for their primality.

However I think that the easiest solution is to obtain a list of every 10 digit prime (using http://www.prime-numbers.org) and then doing a simple analysis against the first hundred digits or so of e.

Doing this will result you with 7427466391. Heading on over to http://7427466391.com will show you a list of four numbers in a sequence and ask you to find the fifth.

The first thing you should realise is that the number you just found is the output of f(4). The second thing you should notice is that the output of f(1) are the first 10 digits of e. That should tell you that this function probably operates on the digits of e.

So what’s the correlation? Could it be some sort of weird reimann’s sum or 3rd order polytronic fit to the 4 other numbers? At first I thought to myself that the relationship had to be some sort of weird and arcane algorithm. However, I quickly put an end to that foolishness and began trying to think like “a google engineer would think.” In my mind I figured that at Google, people are often encouraged to come up with simple solutions to tough problems.

So what’s the simple solution here? “I wonder what the digits add up to”, I thought to myself. Sure enough each output’s digits summed up to 49. Wow, that was easy! You still gotta find the fifth output though.

So I wrote up a little Python script to do all the dirty work. I give you my solution!

#!/bin/env python 

data = 71828182845904523536028747135266249775724709  

def f(x): count = 0 for i in range(len(data)-1): sum = 0 for n in range(10): sum = sum + int(data[i+n])

 if sum == 49: count = count + 1 if count == 5: print data[i:(i+10)] break

All this script does is step through each place in e grabs 10 digits from that offset, sums the digits and if they equal 49, we increment the count. If they wanted the first output, we give them the sum when count == 1 and so on. So to find the fifth output:

[Isabella:~/Documents] phaedo% python Python 2.3 (#1, Sep 13 2003, 00:49:11) [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin Type "help", "copyright", "credits" or "license" for more information. \>\>\> import fx \>\>\> fx.f(1) 7182818284 \>\>\> fx.f(2) 8182845904 \>\>\> fx.f(5) 5966290435 \>\>\> 

The fifth ten-digit-sequence in the digits of e whose digits sum to 49 is 5966290435

Edit: Someone pointed out that I had used f(1) up there in the domain instead of the actual prime (which is f(4)) Thanks!