i used php, which is pretty inefficient in such things. however i started three instances of my script and it did the job without taking too much time:
Splitted pi into substrings and sorted them with a mergesort algorithm I had lying around from school. Then just checked the following value.
Changed the lenght of the substrings manually as I was just trying and got it right immediatly
Takes under 1 Sec (Without Mergesort it takes way longer)
import java.io.File;
import java.util.Scanner;
public class ARepeatOfPi {
public static void main(String[] args) throws Exception{
String Pi = new Scanner( new File("PATH TO PI.TXT") ).useDelimiter("\\A").next();
int n=12;
long[] Piss = new long[Pi.length()-n];
for (int i=0;i<Piss.length;i++){
Piss[i]= Long.parseLong(Pi.substring(i,i+n));
}
mergesort(Piss,0,Piss.length-1);
System.out.println(check(Piss,n));
}
public static long check(long[] Piss, long n){
for (int i=0;i<Piss.length-1;i++){
if (Piss[i]==Piss[i+1]){
return Piss[i];
}
}
return 0;
}
public static void merge(long A[] ,int p, int q, int r) {
int n1, n2;
n1=q-p+1;
n2=r-q;
long L[]=new long[n1+1];
long R[]=new long[n2+1];
for (int i=0; i<n1; i++) L[i] = A[p + i];
for (int j=0; j<n2; j++) R[j] = A[q + j + 1];
L[n1]=Long.MAX_VALUE;
R[n2]=Long.MAX_VALUE;
int i=0;
int j=0;
for (int k=p;k<=r;k++) {
if (L[i]<=R[j]) {
A[k]=L[i];
i=i+1;
}
else {
A[k]=R[j];
j=j+1;
}
}
}
public static void mergesort(long A [], int p, int r) {
if (p<r) {
int q= (p+r)/2;
mergesort(A,p,q);
mergesort(A,q+1,r);
merge(A,p,q,r);
}
}
}
#!/usr/bin/env python3
import os
file=open("pi_1mio1.txt", "r")
pi=file.read()
# random small startvalue
lengrecord=3
longest="123"
def search(start,leng):
global lengrecord, longest
if leng > lengrecord:
lengrecord=leng
longest=start
for i in range(0,10):
i = str(i)
erste = pi.find(start+i)
if erste != -1:
if pi.find(start+i,erste+1) != -1:
search(start+i,leng+1)
start="9"
search(start,3)
print("Longest:"+longest)
I started this 10 times with different start values (0-9) to have it running on multiple CPUs parallel. On my PC it took about 10 minutes.
public class pi {
int[] succ = new int[10];
int back;
static short maxdepth = 13;
/**
* finds longest repeated substring
*/
public static void repeated() {
pi aho [] = new pi[piDigits.length()*maxdepth];
//write("pi_rep.txt",words[maxind]);
aho[0] = new pi(0);
int root = 0, currdepth = 0, nextAlloc=1;
int updpath[] = new int[maxdepth];
int bestmatch=0, besti=0;
for(int i=0;i<piDigits.length();i++) {
int dig="0123456789".indexOf(piDigits.charAt(i));
if (currdepth==maxdepth) {
root=aho[root].back;
currdepth--;
}
int upd=root, upddepth=currdepth;
while ((upddepth>0)&&(aho[upd].succ[dig]==0)) {
updpath[upddepth]=upd;
upd=aho[upd].back;
upddepth--;
}
if (upddepth>bestmatch) {
bestmatch=upddepth;
System.out.printf("New best depth "+bestmatch+" at "+i+"\n");
besti=i;
}
int back=aho[upd].succ[dig];
if (back==0) {// we are at root
aho[nextAlloc] = new pi(0);
aho[upd].succ[dig]=back=nextAlloc++;
}
upddepth++;
while (upddepth<=currdepth) {
aho[nextAlloc] = new pi(back);
aho[updpath[upddepth++]].succ[dig]=back=nextAlloc++;
}
root=back;currdepth++;
}
write("pi_Rep.txt",piDigits.substring(besti-bestmatch,besti+1));
}
}
String pi = new File("Pi_1Mio.txt").text
int max = pi.size()
int len = 1
int index = 0
while(index+len < max) {
while(true) {
int s = pi[index..<max].findAll(pi[index..<index+len]).size()
if(s > 1) {
println "${pi[index..<index+len]} - $s - $len - $index"
len++
}
else {
break
}
}
index++
}