import java.io.*;
//_____________________________________________________________
public class euler
{ 
//_____________________________________________________________
public static final void main(String[] args) throws Exception
{
   euler bnk = new euler();
   bnk.start(args);
}
//___________________________________________________________________________
void start(String[] args)
{
   System.out.println("This proves pattern 95.");
   int start = 1047;
   int offset = 552;
   StringBuffer buf = new StringBuffer();
   if (args.length > 0) start = Integer.parseInt(args[0]);
   if (args.length > 1) offset = Integer.parseInt(args[1]);
   String e = getFile2("euler.txt");
   String pi = "";
   int pos = 0;
   for (int i = 0; i < start; i++)
   {
      buf.append(e.substring(pos,pos+1));
      if ((i % 100 == 0) & (i > 0)) buf.append("<br>\r\n");
      pos++;
   }
   buf.append("<br>\r\n");
   for (int i = 0; i < 10; i++)
   {
      for (int j = 0; j < offset; j++)
      {
         buf.append(e.substring(pos,pos+1));
         if (j % 100 == 0) buf.append("<br>\r\n");
         pos++;
      }
      buf.append("<br>\r\n");
   }
   saveFile("euler.htm",buf.toString(),false);
   for (int i = start; i < start + 10 * offset; i += offset)
   {
      pi += e.substring(i,i+1);
   }
   System.out.println(pi);
}
//___________________________________________________________________________
String getFile2(String file) 
{
   StringBuffer buf=new StringBuffer();
   String str;
  try
  {
   BufferedReader in = new BufferedReader (new FileReader (file));
   while((str=in.readLine())!=null)
   {
      buf.append(str);
   }
   in.close();
  }
  catch (Exception e)
  {
   System.out.println(e);
  }
   return (buf.toString());
}
//___________________________________________________________________________
public static void saveFile(String file, String str, boolean append) 
{
  try
  {
   BufferedWriter out = new BufferedWriter(new FileWriter(file, append));
   out.write(str);
   out.close();
  }
  catch (Exception e)
  {
   System.out.println(e);
  }
}
}//__________________________________________________________________________
