//import java.io.*;
import java.util.*;
import java.net.*;
//_____________________________________________________________
public class adjacent
{ 
   //pseudo Genesis 1:1 "BRAJYO BRA ALHYM AO HJMYM VAO HARE";
   String gen = "BRAJYOBRAALHYMAOHJMYMVAOHARE";
   Random rand = new Random(0);
   int cntall = 0;
   double vtimes = 0;
   int skip = 0;
   String out = "";
//_____________________________________________________________
public static final void main(String[] args) throws Exception
{
   adjacent bnk = new adjacent();
   bnk.start(args);
}
//___________________________________________________________________________
void start(String[] args)
{
   System.out.println("This proves pattern 66.");
   int maxall = 1000;
   if (args.length > 0) maxall = Integer.parseInt(args[0]);
   startit(-1,true);
   for (int i = 0; i < maxall; i++)
   {
      gen = randomstr(28);
      startit(i,false);
   }
   int mult = maxall / cntall;
   System.out.println(" one in " + mult);
}
//___________________________________________________________________________
void startit(int ii,boolean first)
{
   int cnt = 0;
   int v25 = 0;
   int v52 = 0;
   int v37 = 0;
   int v73 = 0;
   for (int i = 0; i < gen.length(); i++)
   {
      for (int j = i + 1; j < gen.length()+1; j++)
      {
         String str = gen.substring(i,j);
         int val = value(str);
         if (val % 25 == 0) v25++;
         if (val % 52 == 0) v52++;
         if (val % 37 == 0) v37++;
         if (val % 73 == 0) v73++;
         cnt++;
      }
   }
   double perc25 = (double)v25 / ((double)cnt / 25.0);
   double perc52 = (double)v52 / ((double)cnt / 52.0);
   double perc37 = (double)v37 / ((double)cnt / 37.0);
   double perc73 = (double)v73 / ((double)cnt / 73.0);
   if (first) vtimes = perc37*perc73;
   if ((perc25*perc52) > vtimes) cntall++;
}
//___________________________________________________________________________
String randomstr(int len)
{
   String alphabet = "ABGDHVZCTYKLMNSIFEQRJO";
   StringBuffer buf = new StringBuffer();
   for (int i = 0; i < len; i++)
   {
      int pos = rand.nextInt(22);
      String s = alphabet.substring(pos,pos+1);
      buf.append(s);
   }
   return(buf.toString());
}
//__________________________________________________
int value(String str)
{
   int total = 0;
   out = "";
   for (int i = 0; i < str.length(); i++)
   {
      int v = 0;
      String st2 = str.substring(i,i+1);
      byte[] st3 = st2.getBytes();
      byte st = st3[0];
      if (st == 'a') v = 1;
      else if (st == 'b') v = 2;
      else if (st == 'c') v = 3;
      else if (st == 'd') v = 4;
      else if (st == 'e') v = 5;
      else if (st == 'f') v = 6;
      else if (st == 'g') v = 7;
      else if (st == 'h') v = 8;
      else if (st == 'i') v = 9;
      else if (st == 'j') v = 10;
      else if (st == 'k') v = 20;
      else if (st == 'l') v = 30;    
      else if (st == 'm') v = 40;
      else if (st == 'n') v = 50;
      else if (st == 'o') v = 60;
      else if (st == 'p') v = 70;
      else if (st == 'q') v = 80;
      else if (st == 'r') v = 90;
      else if (st == 's') v = 100;
      else if (st == 't') v = 200;
      else if (st == 'u') v = 300;
      else if (st == 'v') v = 400;
      else if (st == 'w') v = 500;
      else if (st == 'x') v = 600;
      else if (st == 'y') v = 700;
      else if (st == 'z') v = 800;
      else if (st == 'A') v = 1;
      else if (st == 'B') v = 2;
      else if (st == 'G') v = 3;
      else if (st == 'D') v = 4;
      else if (st == 'H') v = 5;
      else if (st == 'V') v = 6;
      else if (st == 'Z') v = 7;
      else if (st == 'C') v = 8;
      else if (st == 'T') v = 9;
      else if (st == 'Y') v = 10;
      else if (st == 'K') v = 20;
      else if (st == 'L') v = 30;
      else if (st == 'M') v = 40;
      else if (st == 'N') v = 50;
      else if (st == 'S') v = 60;
      else if (st == 'I') v = 70;
      else if (st == 'F') v = 80;
      else if (st == 'E') v = 90;
      else if (st == 'Q') v = 100;
      else if (st == 'R') v = 200;
      else if (st == 'J') v = 300;
      else if (st == 'O') v = 400;
      total += v;
      if (i > 0) out += " + ";
      out += Integer.toString(v);
   }
   return(total);
}
}//__________________________________________________________________________
