import java.io.*;
import java.util.*;
import java.net.*;
//_____________________________________________________________
public class sqrt
{ 
   static byte[] pi = getBytes("pi.num");
   static byte[] e = getBytes("e.num");
   static byte[] phi = getBytes("phi.num");
   static byte[] sqrt2 = getBytes("sqrt2.num");
//_____________________________________________________________
public static final void main(String[] args) throws Exception
{
   sqrt bnk = new sqrt();
   System.out.println("This proves pattern 97.");
   System.out.println("------------------ pi -------------------");
   bnk.start2(args,pi);
   System.out.println("------------------ e -------------------");
   bnk.start2(args,e);
   System.out.println("------------------ phi -------------------");
   bnk.start2(args,phi);
   System.out.println("------------------ sqrt2 -------------------");
   bnk.start2(args,sqrt2);
}
//___________________________________________________________________________
void start2(String[] args, byte[] bb)
{  
   thestart("314159",bb);
   thestart("271828",bb);
   thestart("161803",bb);
   thestart("141421",bb);
   if (args.length > 0) thestart(args[0],bb);
}
//___________________________________________________________________________
void thestart(String look, byte[] bb)
{
   for (int i = 1; i < 1000; i++)
   {
      for (int j = 1; j < 100; j++)
      {
         startit(i,j,look,bb);
      }
   }
}
//___________________________________________________________________________
void startit(int start, int offset, String look, byte[] bb)
{
   StringBuffer buf = new StringBuffer();
   for (int i = 0; i < look.length(); i++)
   {
      int pos = start + (offset * i);
      buf.append((char)bb[pos]);
   }
   if (buf.toString().equals(look))
   {
      System.out.println(start + " " + offset + " " + buf.toString());
      String verses = Integer.toString(start) + Integer.toString(offset);
      String[] out = new String[1];
      out[0] = verses;
      verse vers = new verse();
      vers.start(out);
   }
}
//___________________________________________________________________________
public static byte[] getBytes(String name) 
{
   byte[] b = new byte[0];
  try
  {
   File file = new File(name);
   b = new byte[(int) file.length()];
   FileInputStream fileInputStream = new FileInputStream(file);
   fileInputStream.read(b);
  }
  catch (Exception e)
  {
   System.out.println(e);
  }
   return(b);
}
}//__________________________________________________________________________
