# A Candle in the Dark

A look on science, politics, religion and events

## Abstruse Goose Puzzle

You might have come across Abstruse Goose before. It’s simply a wonderful webcomic, along the lines of xkcd, but much more technical. Each comic strip usually contains an allusion to some physical or mathematical concept and ends with a humorous punchline.

Today’s comic had a simple puzzle. And, as I was curious about where it was leading, and had time to kill, I took a shot at it.

And how does one go solving this? It is fairly easy. In fact, all you need is to know is the first n digits of e and after that, it’s simply string manipulation and prime number checking.

I’ve embedded the C++ code which I used to solve the puzzle at the end of the post, below the fold.

It’s easier to find the first 100,000 digits of e using a quick search in google than to generate it. Once you have the string, you just need to check if every set of 10 consecutive digits is prime. Turns out, that the first 10 digit prime number found in consecutive digits of e is 7427466391.

That’s Clue #1 done. Proceeding to the url, we get Clue #2:

Again, very easy, and all that’s needed now is the first n digits of pi instead of e. The first 10 digit prime number found in consecutive digits of pi turns out to be 5926535897 (occurs very early!), leading to the final Clue #3.

I’ll leave you to do this one, and appreciate the punchline.

Code below the fold

`Thanks to `rcw and gwillen for spotting the bug!
``` #include<fstream> #include<iostream> #include<stdlib.h> #include<math.h> using namespace std; int main() { ifstream ifile; ifile.open("e.txt"); unsigned long long int nb; unsigned long long int limit; unsigned long long int test; const int length=10; char *buffer; char c; buffer=new char[length]; for(int i=0;i<90000;i++) { //Read sets of 10 numbers from the file ifile.seekg(ios::beg+i); ifile.read(buffer,length); nb=0; for(int rr=0;rr<length;rr++) { c=buffer[rr]; test=((int)c)-((int)'0'); for(int qq=length-1;qq>rr;qq=qq-1) test=test*10; nb=nb+test; }```

```//Check if the number is prime limit=sqrt(nb)+1; test=0; if(nb%2==0) {test=1; continue;} else {for(int rr=3;rr<limit;rr=rr+2) if (nb%rr==0) {test=1; break;}} if(test==1) continue; else {cout<<"First "<<length<<" digit prime in pi is: "<<nb<<endl; exit(0); } }````return 0;``}`

Written by parseval

March 6, 2009 at 11:40 pm

Posted in mathematics, programming

Tagged with

### 9 Responses

1. blah…. at least you should have waited a few days before posting solution

alexandru

March 7, 2009 at 1:56 am

2. SPOILER WARNING:

Vf gur oht va gur pbqr orybj gur sbyq qryvorengr?

gwillen

March 7, 2009 at 4:11 am

• SPOILER WARNING:

Vf gur oht va gur pbqr orybj gur sbyq qryvorengr?

No, the bug wasn’t deliberate. I think something went wrong with the – sign while I copy/pasted into the code tag. Thanks for the alert! Although, now that you mention it, I think I will leave it there, so people can figure it out đź™‚

parseval

March 7, 2009 at 5:03 am

3. tjvyyra jnf gnyxvat nobhg nabgure oht nygbtrgure – V thrff lbh pbhyq fnl guvf pbqr vf n zbqhyhf bs gur shyy fbyhgvba

rcw

March 7, 2009 at 6:03 am

• tjvyyra jnf gnyxvat nobhg nabgure oht nygbtrgure – V thrff lbh pbhyq fnl guvf pbqr vf n zbqhyhf bs gur shyy fbyhgvb

Hm.. what other bug, the return 0 one? I don’t think it’ll matter? Also, the ROT13 goes to my spam folder. Is it possible to comment in plain english?

I’ve listed only the code to calculate from digits of pi and e, so it’s definitely not the full solution. However, it makes it easy to go to the final url.

parseval

March 7, 2009 at 6:48 am

4. rr<length should be rr<limit. As is, the code thinks 281828459 is prime because it doesn’t have any factors less than 9.

rcw

March 7, 2009 at 2:45 pm

5. Err, only the second rr<length

rcw

March 7, 2009 at 2:46 pm

6. Err, only the second rr<length

Absolutely.

The < sign and variable got mangled when I copy/pasted, and I filled it back wrong. Thanks

parseval

March 7, 2009 at 3:45 pm

7. This might be a bit easier to get working. The first parameter is number of digits you are testing for, the last is the file name with your number (e or pi):

#!/usr/bin/ruby
#
#

class Numeric
def sqrt
Math.sqrt self
end
end

def isPrime?(number)
number.sqrt.floor.step 2,-1 do |x|
return false if number % x == 0
end

return true
end

file = File.open(ARGV[1], “r”)
puts “Initial Window: #{window}\n”

counter = 0
counter = counter + 1
puts counter if counter % 10 == 0
if isPrime? window.to_i then
puts window
puts “Found at position #{counter}”
break
end

window = window[1..window.length-1] + n
end

vace117

March 7, 2009 at 5:45 pm