import java.io.*;
import java.net.*;
import java.util.zip.*;
//_____________________________________________________________
public class look
{ 
//_____________________________________________________________
public static final void main(String[] args) throws Exception
{
   look bnk = new look();
   bnk.start2(args);
}
//_____________________________________________________________
look() throws Exception 
{
}
//___________________________________________________________________________
void start2(String[] args) throws Exception
{
   String name = "e";
   getit(name);
   unzip(name,"out");
   String file = getFile2("out/e - Dec.txt");
   start("7392637",file,name);
   name = "pi";
   getit(name);
   unzip(name,"out");
   file = getFile2("out/pi - Dec.txt");
   start3("4352536",file,name);
}
//___________________________________________________________________________
void start3(String str, String file, String name)
{
   int pos = 0;
   for (int i = 0; i < 1000; i++)
   {
      pos = file.indexOf(str,pos+1);
      if (pos < 0) break;
      String posstr = Integer.toString(pos);
      if (posstr.indexOf("73") >= 0)
      {
         System.out.println(str + " found at position " + pos + " in " + name);
         break;
      }
   }
}
//___________________________________________________________________________
void start(String num, String file, String name)
{
   int pos = 0;
   for (int i = 0; i < 1000; i++)
   {
      pos = file.indexOf(num,pos+1);
      if (pos < 0) break;
      String str = Integer.toString(pos+0);
      int pos1 = str.indexOf("37");
      int pos2 = str.indexOf("73");
      int delta = Math.abs(pos1 - pos2);
      if ((pos1 >= 0) & (pos2 >= 0) & (delta > 1))
      {
         System.out.println(num + " found at " + str + " in " + name);
      }
   }
}

//___________________________________________________________________________
void getit(String name) throws Exception
{
   if (fileexists("" + name + ".zip")) return;
   String namein = "https://archive.org/download/Math_Constants/" + name + ".zip";
   byte[] bb2 = getUrlBytes(namein);
   saveBytes("" + name + ".zip",bb2);
}
//___________________________________________________________________________
byte[] getUrlBytes(String name) throws Exception
{
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   InputStream is = null;
   URL url = new URL(name);
   is = url.openStream ();
   byte[] byteChunk = new byte[4096]; 
   int n;
   while ( (n = is.read(byteChunk)) > 0 ) 
   {
      baos.write(byteChunk, 0, n);
   }
   is.close(); 
   byte[] bb = baos.toByteArray();
   return(bb);
}
//___________________________________________________________________________
void saveBytes(String file, byte[] str) 
{

   try (FileOutputStream fos = new FileOutputStream(file)) 
   {
      fos.write(str);
      fos.close(); 
   }
  catch (Exception e)
  {
   System.out.println(e);
  }
}
//___________________________________________________________________________
boolean fileexists(String name)
{
   File f = new File(name);
   if(f.exists() && !f.isDirectory()) return(true);
   else return(false);
} 
//___________________________________________________________________________
void unzip(String name, String dirname) throws Exception
{
   File dir = new File(dirname);
   if(!dir.exists()) dir.mkdirs();
   File file2 = new File(dirname + "/" + name + ".zip");
   if (file2.exists()) return;
   FileInputStream fis;
   byte[] buffer = new byte[1024];
   fis = new FileInputStream(name + ".zip");
   ZipInputStream zis = new ZipInputStream(fis);
   ZipEntry ze = zis.getNextEntry();
   while(ze != null)
   {
      String fileName = ze.getName();
      File newFile = new File(dirname + File.separator + fileName);
      new File(newFile.getParent()).mkdirs();
      FileOutputStream fos = new FileOutputStream(newFile);
      int len;
      while ((len = zis.read(buffer)) > 0) 
      {
         fos.write(buffer, 0, len);
      }
      fos.close();
      zis.closeEntry();
      ze = zis.getNextEntry();
   }
   zis.closeEntry();
   zis.close();
   fis.close();
}
//___________________________________________________________________________

String getFile2(String file) throws Exception
{
   StringBuffer buf=new StringBuffer();String str;
   BufferedReader in = new BufferedReader (new FileReader (file));
   while((str=in.readLine())!=null)
   {
      buf.append(str);
   }
   in.close();
   return (buf.toString());
}
}//__________________________________________________________________________
