Advertisement
Creamsteak

Test3b

Sep 9th, 2011
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.74 KB | None | 0 0
  1. import java.math.BigInteger;
  2. import java.io.*;
  3. import java.util.*;
  4.  
  5. class test3b {
  6.     public static void main(String args[]) {
  7.  
  8.         //Memory
  9.         int matrix[][] = new int[3][3];
  10.         int picked[][] = new int[3][3];
  11.  
  12.         int score=0;
  13.         int set=0;
  14.  
  15.         Integer superscore = new Integer("0");
  16.         BigInteger prob = new BigInteger("0");
  17.         BigInteger MiniBoss = new BigInteger("0");
  18.         BigInteger BigBoss = new BigInteger("0");
  19.  
  20.         int sorter[] = new int[9];
  21.  
  22.         //For each possible combination... Comments are time taken to evaluate per level
  23.         for(int n1=1;n1<=9;n1++)
  24.         for(int n2=1;n2<=9;n2++)
  25.         for(int n3=1;n3<=9;n3++)
  26.         for(int n4=1;n4<=9;n4++)
  27.         for(int n5=1;n5<=9;n5++)
  28.         for(int n6=1;n6<=9;n6++)
  29.         for(int n7=1;n7<=9;n7++)
  30.         for(int n8=1;n8<=9;n8++)
  31.         for(int n9=1;n9<=9;n9++){
  32.  
  33.             //Builds the matrix and the picked list
  34.             matrix =  new int[][] {{n1,n2,n3},{n4,n5,n6},{n7,n8,n9}};
  35.             sorter = new int[]{n1,n2,n3,n4,n5,n6,n7,n8,n9};
  36.             Arrays.sort(sorter);
  37.             score = 0;
  38.  
  39.             //Set Repicked
  40.             for(int i=0;i<3;i++)
  41.             for(int j=0;j<3;j++){
  42.                 picked[i][j]=0;
  43.             }
  44.  
  45.             //for the lowest 3 values
  46.             for(int i=0;i<3;i++){
  47.                 set=0;
  48.                 for(int j=0;j<3;j++)
  49.                 for(int k=0;k<3;k++){
  50.                     if(matrix[j][k] == sorter[i] && picked[j][k]==0 && set==0){
  51.                         picked[j][k]=1;
  52.                         set=1;
  53.                     }
  54.                 }
  55.             }
  56.  
  57.             //If the three picked values are in a single row or column...
  58.             if( picked[0][0]+picked[0][1]+picked[0][2]==3 ||
  59.                 picked[1][0]+picked[1][1]+picked[1][2]==3 ||
  60.                 picked[2][0]+picked[2][1]+picked[2][2]==3 ||
  61.                 picked[0][0]+picked[1][0]+picked[2][0]==3 ||
  62.                 picked[0][1]+picked[1][1]+picked[2][1]==3 ||
  63.                 picked[0][2]+picked[1][2]+picked[2][2]==3 )
  64.             {
  65.                 score = sorter[8]+sorter[7]+sorter[6]+sorter[5]+sorter[4]+sorter[2];
  66.             } else {
  67.                 score = sorter[8]+sorter[7]+sorter[6]+sorter[5]+sorter[4]+sorter[3];
  68.             }
  69.  
  70.             //System.out.println(n1+","+n2+","+n3+"     "+picked[0][0]+","+picked[0][1]+","+picked[0][2]);
  71.             //System.out.println(n4+","+n5+","+n6+"     "+picked[1][0]+","+picked[1][1]+","+picked[1][2]);
  72.             //System.out.println(n7+","+n8+","+n9+"     "+picked[2][0]+","+picked[2][1]+","+picked[2][2]);
  73.             //System.out.println();
  74.             //System.out.println(score);
  75.             //System.out.println();
  76.  
  77.             superscore = new Integer(score);
  78.             MiniBoss = new BigInteger(superscore.toString());
  79.             BigBoss = BigBoss.add(MiniBoss);
  80.             prob = prob.add(new BigInteger("1"));
  81.  
  82.             //System.out.println(score+" "+prob.toString()+" "+BigBoss.toString());
  83.             //System.out.println();
  84.  
  85.         }
  86.  
  87.         try {
  88.             BufferedWriter out = new BufferedWriter(new FileWriter("test3b-output.txt"));
  89.             out.write(
  90.                 "BigBoss = "+BigBoss.toString()+
  91.                 " BigCount = "+prob.toString()
  92.             );
  93.             out.close();
  94.         } catch (IOException e){}
  95.  
  96.     }
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement