
import java.io.*;
import java.util.*;

public class Generator_palindromes  {
  public static void main(String args[]) throws Exception  {
	 final int STRING_LENGTH =40;
	 final int NUM_EXAMPLES = 500;   //  # of pos. examples which equals # of neg.
	                                  //  examples and # of pos. test examples, and
	                                  //  # of neg. test examples.  Thus total # of
	                                  //  examples = 4 times NUM_EXAMPLES.

	// int [] BTSP = new int[NUMBITS];
	 String st="";

	 final long RANDOM_SEED = 3178649;

	 Random random_gen = new Random(RANDOM_SEED);

	  // First few bits are completely random; enough random bits for multiplexor input

  try
    {
      PrintStream outputTrainPOS = new PrintStream(new FileOutputStream("trainPOS.txt"));
      PrintStream outputTrainNEG = new PrintStream(new FileOutputStream("trainNEG.txt"));
      PrintStream outputTestPOS = new PrintStream(new FileOutputStream("testPOS.txt"));
      PrintStream outputTestNEG = new PrintStream(new FileOutputStream("testNEG.txt"));

      //  Generate training set, both pos and neg examples.
        // First pos. training set
        for(int i=0; i<NUM_EXAMPLES; i++)  {
		 // Generate a random half string.
		 st="";
		 for(int pos = 0; pos < STRING_LENGTH/2; pos++)
             if(random_gen.nextInt(20)< 10)
		   	        st += "1";
		   	        else st += "0";
		 for(int pos = STRING_LENGTH/2; pos < STRING_LENGTH; pos++)
             st += st.substring(STRING_LENGTH-pos-1,STRING_LENGTH-pos);
	     outputTrainPOS.println(st);
	 }
        // Then neg. training set
        for(int i=0; i<NUM_EXAMPLES; i++)  {
		 // Generate a random string.
		 st="";
		 for(int pos = 0; pos < STRING_LENGTH; pos++)
             if(random_gen.nextInt(20)< 10)
		   	        st += "1";
		   	        else st += "0";
         outputTrainNEG.println(st);
	 }
      //  Generate test set, both pos and neg examples.
        // First pos. test set
        for(int i=0; i<NUM_EXAMPLES; i++)  {
		 // Generate a random half string.
		 st="";
		 for(int pos = 0; pos < STRING_LENGTH/2; pos++)
             if(random_gen.nextInt(20)< 10)
		   	        st += "1";
		   	        else st += "0";
		 for(int pos = STRING_LENGTH/2; pos < STRING_LENGTH; pos++)
             st += st.substring(STRING_LENGTH-pos-1,STRING_LENGTH-pos);
	     outputTestPOS.println(st);
	 }
        // Then neg. test set
        for(int i=0; i<NUM_EXAMPLES; i++)  {
		 // Generate a random string.
		 st="";
		 for(int pos = 0; pos < STRING_LENGTH; pos++)
             if(random_gen.nextInt(20)< 10)
		   	        st += "1";
		   	        else st += "0";
         outputTestNEG.println(st);
	 }
      outputTrainPOS.flush();
      outputTrainPOS.close();
      outputTrainNEG.flush();
      outputTrainNEG.close();
      outputTestPOS.flush();
      outputTestPOS.close();
      outputTestNEG.flush();
      outputTestNEG.close();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }
  private static boolean conceptMember(String instance){
	  if(unitation(instance) > instance.length()/2)
	    return true;
	    else return false;
  }
  private static int unitation(String instance){
	  int numOnes=0;
	  for(int k=0; k < instance.length(); k++)
	      if(instance.charAt(k)=='1') numOnes++;
	  return numOnes;
  }
}
