Pi Hunting - find an index of Pi whose value matches its index Given π to an arbitrary number of places, your challenge is to locate indices of π where the index (1,2,3,4...) and the string of numbers from that index carry the same value for the length of the index.

That sounds complex, so let's look at an example!

Indices will count from +1 upwards through natural whole integers, skipping 0 as the first index:

1, 2, 3, 4,.... up to an arbitrary whole positive number.

If the number being used (instead of π) was:

123456789101112

then for each index value 1... the sequence of numbers at that index position would match with the value of the index.

At position 1 the string '1' can be found

123456789101112
^


At position 2 the string '2' can be found

123456789101112
 ^


If this sequence continue to 10, you'd find that at position 10 the sequence '10' is found.

123456789101112
         ^


However, when you reach position 11, you find '01', not '11'.

123456789101112
          ^


Given an input value of π of the format:

3.14159...

and taking off 3. to give 14159... using indices start at 1, so the first string found at index 1 is "1", the first string found at index 2 is "4", etc.

Find the shortest code to locate the first 4 indices where the set of characters at that index position have the same numerical sequence as the numbers that make up the index.

Shortest wins!

Built-ins are allowed

Examples of finding the nth digit of pi:

Find the nth decimal of pi

The major step here is to make the comparison of the nth digit and 'n' to determine if there's a match.

** First Match **

3.14159265

1 : finds '1'

A simple psuedo-code approach might be similar to the following, except this one doesn't account for "3." or the index being off by 1:

assume input=pi to any arbitrary length supported with '3.' removed

for(var index=0, maximumInputLength=input.length; index &lt; maxmimumInputLength; index++) {
 var indexString = '' + i;
 var indexLength = indexString.length;
 if(indexString.substr(index, indexLength) == indexString) {
    // index found at index'th position
 } else {
    // index not found at index'th position
 }
}


This style of solution will return '6' found in the 6th index position and '27' found in the 27th index position.

Given 141 592 6 (6 is in the 7th position starting at 0).

To verify if an answer is correct, you can use the above code to find the nth digit of pi and compare to the value of 'n' in your language of choice!

Thank you for the great feedback in helping me write a better first question.

Clarifications:


Is π given as an input - YES
Python 2, 64 bytes

i=1
while i&lt;len(P):
&#9;if int(P[i:i+len(str(i))])==i:print i
&#9;i+=1

As you said, pi's digits are given, so I chose the variable P to contain the entire digit string.
The full code first downloads one billion digits of pi to a file using cURL and then reads in that file to process it.

&quot;Setting up pi's digits.&quot;; exec'import os\nN,f=200000000,&quot;pi.txt&quot;\nif not os.path.exists(f):os.system(&quot;curl https://stuff.mit.edu/afs/sipb/contrib/pi/pi-billion.txt&gt;&quot;+f)\nP=open(f,&quot;r&quot;).read()[1:N+2][:-1]'
&quot;Search through pi.&quot;;      exec'i=1\nwhile i&lt;len(P):\n\tif int(P[i:i+len(str(i))])==i:print i\n\ti+=1'

Though, when one knows the answer, a simple plaintext output is actually shorter (29 bytes).

print&quot;1,16470,44899,79873884&quot;

This series of numbers is also known to the OEIS (http://oeis.org/A057680).