Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigInteger;
- import java.io.*;
- import java.util.*;
- class test3b {
- public static void main(String args[]) {
- //Memory
- int matrix[][] = new int[3][3];
- int picked[][] = new int[3][3];
- int score=0;
- int set=0;
- Integer superscore = new Integer("0");
- BigInteger prob = new BigInteger("0");
- BigInteger MiniBoss = new BigInteger("0");
- BigInteger BigBoss = new BigInteger("0");
- int sorter[] = new int[9];
- //For each possible combination... Comments are time taken to evaluate per level
- for(int n1=1;n1<=9;n1++)
- for(int n2=1;n2<=9;n2++)
- for(int n3=1;n3<=9;n3++)
- for(int n4=1;n4<=9;n4++)
- for(int n5=1;n5<=9;n5++)
- for(int n6=1;n6<=9;n6++)
- for(int n7=1;n7<=9;n7++)
- for(int n8=1;n8<=9;n8++)
- for(int n9=1;n9<=9;n9++){
- //Builds the matrix and the picked list
- matrix = new int[][] {{n1,n2,n3},{n4,n5,n6},{n7,n8,n9}};
- sorter = new int[]{n1,n2,n3,n4,n5,n6,n7,n8,n9};
- Arrays.sort(sorter);
- score = 0;
- //Set Repicked
- for(int i=0;i<3;i++)
- for(int j=0;j<3;j++){
- picked[i][j]=0;
- }
- //for the lowest 3 values
- for(int i=0;i<3;i++){
- set=0;
- for(int j=0;j<3;j++)
- for(int k=0;k<3;k++){
- if(matrix[j][k] == sorter[i] && picked[j][k]==0 && set==0){
- picked[j][k]=1;
- set=1;
- }
- }
- }
- //If the three picked values are in a single row or column...
- if( picked[0][0]+picked[0][1]+picked[0][2]==3 ||
- picked[1][0]+picked[1][1]+picked[1][2]==3 ||
- picked[2][0]+picked[2][1]+picked[2][2]==3 ||
- picked[0][0]+picked[1][0]+picked[2][0]==3 ||
- picked[0][1]+picked[1][1]+picked[2][1]==3 ||
- picked[0][2]+picked[1][2]+picked[2][2]==3 )
- {
- score = sorter[8]+sorter[7]+sorter[6]+sorter[5]+sorter[4]+sorter[2];
- } else {
- score = sorter[8]+sorter[7]+sorter[6]+sorter[5]+sorter[4]+sorter[3];
- }
- //System.out.println(n1+","+n2+","+n3+" "+picked[0][0]+","+picked[0][1]+","+picked[0][2]);
- //System.out.println(n4+","+n5+","+n6+" "+picked[1][0]+","+picked[1][1]+","+picked[1][2]);
- //System.out.println(n7+","+n8+","+n9+" "+picked[2][0]+","+picked[2][1]+","+picked[2][2]);
- //System.out.println();
- //System.out.println(score);
- //System.out.println();
- superscore = new Integer(score);
- MiniBoss = new BigInteger(superscore.toString());
- BigBoss = BigBoss.add(MiniBoss);
- prob = prob.add(new BigInteger("1"));
- //System.out.println(score+" "+prob.toString()+" "+BigBoss.toString());
- //System.out.println();
- }
- try {
- BufferedWriter out = new BufferedWriter(new FileWriter("test3b-output.txt"));
- out.write(
- "BigBoss = "+BigBoss.toString()+
- " BigCount = "+prob.toString()
- );
- out.close();
- } catch (IOException e){}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement