Estou tentando fazer uma simulação de todas as combinações possíveis da mega-sena, porém ainda está precário de optimização.
O algoritmo está correto, se alguém tiver alguma ideia para optimização do mesmo eu ficarei grato.
public void calculate(){
int a = 0, b = 0, c = 0, d = 0,e = 0,f = 0;
long[][] array = new long[5000000][6];
int index = 1; // current index of array.
int nRepeat = 0;
long time = System.currentTimeMillis();
for(a = 1; a <= 60; a++){
if(a == b || a == c || a == d || a == e || a == f) continue;
for(b = 1; b <= 60; b++){
if(b == a || b == c || b == d || b == e || b == f) continue;
for(c = 1; c <= 60; c++){
if(c == a || c == b || c == d || c == e || c == f) continue;
for(d = 1; d <= 60; d++){
if(d == a || d == b || d == c || d == e || d == f) continue;
for(e = 1; e <= 60; e++){
if(e == a || e == b || e == c || e == d || e == f) continue;
for(f = 1; f <= 60; f++){
if(f == a || f == b || f == c || f == d || f == e) continue;
boolean A_ = false, B_ = false, C_ = false, D_ = false, E_ = false, F_ = false;
// Start on 1, because cont 0 is correct.
for(int i = 0; i < array.length; i++){
A_ = false; B_ = false; C_ = false; D_= false; E_ = false; F_ = false;
if(count == 0){
array[0][0] = a; array[0][1] = b; array[0][2] = c; array[0][3] = d; array[0][4] = e; array[0][5] = f;
break;
}
if(array[i][0] == 0) break;
/* This method is to check if this combination is equal with some other. */
//check A.
for(int j = 0; j < 6; j++){
if(a == array[i][j]) A_ = true; }
//check B.
for(int j = 0; j < 6; j++){
if(b == array[i][j]) B_ = true;
}
//check C.
for(int j = 0; j < 6; j++){
if(c == array[i][j]) C_ = true;
}
//check D.
for(int j = 0; j < 6; j++){
if(d == array[i][j]) D_ = true;
}
//check E.
for(int j = 0; j < 6; j++){
if(e == array[i][j]) E_ = true;
}
//check F.
for(int j = 0; j < 6; j++){
if(f == array[i][j]) F_ = true;
}
if(A_ == true && B_ == true && C_ == true && D_ == true && E_ == true && F_ == true) break;
} // end for.
long finalTime = System.currentTimeMillis();
++totalN;
/* IF this method to be equals jump to next loop. */
if(A_ == true && B_ == true && C_ == true && D_ == true && E_ == true && F_ == true) {
System.out.printf("\t"+a+"|"+b+"|"+c+"|"+d+"|"+e+"|"+f+" |\t Current Count: "+count+" |\t Repeat Numbers :"+nRepeat+" |\t Current Time: %.2f (minutes) |\t Total Number: "+totalN+" |\t ## This combination is repeated! ## \n", (finalTime - time) / 1000f / 60f );
nRepeat++;
continue;
}
if(count != 0){
array[index][0] = a; array[index][1] = b; array[index][2] = c; array[index][3] = d; array[index][4] = e; array[index++][5] = f;
}
finalTime = System.currentTimeMillis();
++count;
System.out.printf("\t"+a+"|"+b+"|"+c+"|"+d+"|"+e+"|"+f+" |\t Current Count: "+count+" |\t Repeat Numbers :"+nRepeat+" |\t Current Time: %.2f (minutes) |\t Total Number: "+totalN+" |\t ## This combination is available! ## \n", (finalTime - time) / 1000f / 60f );
} // f.
} // e.
} // d.
} // c.
} // b.
}//a.
}