Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- int g_grid[6][6];
- //relleno campo
- void rell (int i, int j, int value)
- {
- printf("%i\n", value);
- g_grid[i][j]=value;
- }
- //rellenar una columna entera
- void rell_grid_1 (int check, int j, int com)
- {
- if(check == 1)
- {
- g_grid[1][j] = com;
- g_grid[2][j] = com +1;
- g_grid[3][j] = com +2;
- g_grid[4][j] = com +3;
- }
- else if (check == 2)
- {
- g_grid[1][j] = com;
- g_grid[2][j] = com -1;
- g_grid[3][j] = com -2;
- g_grid[4][j] = com -3;
- }
- else if (check == 3)
- {
- g_grid[j][1] = com;
- g_grid[j][1] = com +1;
- g_grid[j][1] = com +2;
- g_grid[j][1] = com +3;
- }
- else if (check == 4)
- {
- g_grid[j][1] = com;
- g_grid[j][2] = com -1;
- g_grid[j][3] = com -2;
- g_grid[j][4] = com -3;
- }
- }
- //chequeo numero iguales
- void check_rep_num (int case_, int value_)
- {
- int fil;
- int col;
- int i;
- fil = 0;
- col = 0;
- i=1;
- while (i<=4)
- {
- if(!((g_grid[1][i] == value_)||(g_grid[2][i]==value_)||(g_grid[3][i]==value_)||(g_grid[4][i]==value_)))
- col = i;
- if(!((g_grid[i][1]== value_)||(g_grid[i][2]==value_)||(g_grid[i][3]==value_)||(g_grid[i][4]==value_)))
- fil = i;
- //printf("%i %i %i %i\n", g_grid[i][1], g_grid[i][2], g_grid[i][3], g_grid[i][4]);
- i++;
- }
- //printf("%i %i \n", fil,col);
- g_grid[fil][col]=value_;
- }
- //chequeo numeros distintos
- void check_rell_fil_col (int fc, int value_fc , int value_)
- {
- int i;
- i = 1;
- if (fc == 1)
- {
- while (i<=4)
- {
- if(g_grid[value_fc][i] == 0)
- break;
- //printf("%i %i %i %i\n", g_grid[i][1], g_grid[i][2], g_grid[i][3], g_grid[i][4]);
- i++;
- }
- printf("%i %i \n", fc,i);
- g_grid[value_fc][i]=value_;
- }else if (fc == 2)
- {
- while (i<=4)
- {
- if(g_grid[i][value_fc] == 0)
- break;
- //printf("%i %i %i %i\n", g_grid[i][1], g_grid[i][2], g_grid[i][3], g_grid[i][4]);
- i++;
- }
- printf("%i %i \n", fc,i);
- g_grid[i][value_fc]=value_;
- }
- }
- // check_three
- void check_three_num (void)
- {
- int count = 0;
- int aux = 0;
- int i = 1;
- int j = 1;
- while (i<=4)
- {
- while (j<=4)
- {
- //printf("%i %i %i \n", g_grid[i][j], i, j);
- if (g_grid[i][j]==4)
- count++;
- j++;
- }
- j=1;
- i++;
- }
- //printf("%i\n", count);
- if (count==3){
- check_rep_num(1, 4);
- }
- }
- // check diff
- void check_diff (void)
- {
- int count = 0;
- int aux = 0;
- int i = 1;
- int j = 1;
- //filas
- while(j<=4)
- {
- while (i<=4)
- {
- if (g_grid[j][i]!=0)
- {
- count++;
- aux = aux + g_grid[j][i];
- }
- i++;
- }
- if (count==3){
- printf("%i %i \n", j, aux);
- //check_rep_num(2, 10-aux);
- check_rell_fil_col(1, j, 10-aux);
- }
- count = 0;
- aux = 0;
- i = 1;
- j++;
- }
- count = 0;
- aux = 0;
- i = 1;
- j = 1;
- //columnas
- while(j<=4)
- {
- while (i<=4)
- {
- if (g_grid[i][j]!=0)
- {
- count++;
- aux = aux + g_grid[i][j];
- }
- i++;
- }
- if (count==3){
- //printf("%i %i \n", j, aux);
- //check_rep_num(2, 10-aux);
- check_rell_fil_col(2, j, 10-aux);
- }
- count = 0;
- aux = 0;
- i = 1;
- j++;
- }
- }
- void solver (void)
- {
- //1. caso 4 frente 1
- int j = 1;
- int i = 1;
- int count = 0;
- int count_1 = 0;
- int aux = 0;
- while (j <= 4)
- {
- if((g_grid[0][j]==4)&&(g_grid[5][j]==1))
- rell_grid_1 (1, j, 1);
- if((g_grid[5][j]==4)&&(g_grid[0][j]==1))
- rell_grid_1 (2, j, 4);
- if((g_grid[j][0]==4)&&(g_grid[j][5]==1))
- rell_grid_1 (3, j, 1);
- if((g_grid[j][5]==4)&&(g_grid[j][0]==1))
- rell_grid_1 (4, j, 4);
- j++;
- }
- j = 1;
- //2. caso 1 - rellenar "4"
- while (j <= 4)
- {
- if(g_grid[0][j]==1)
- rell(1, j,4);
- if(g_grid[5][j]==1)
- rell(4, j,4);
- if(g_grid[j][0]==1)
- rell(j, 1,4);
- if(g_grid[j][5]==1)
- rell(j, 4,4);
- j++;
- }
- j = 1;
- //3. caso 2 frente 3 -> poner 4 en la tercera posicion
- while (j <= 4)
- {
- if((g_grid[0][j]==2)&&(g_grid[5][j]==3))
- rell(2, j, 4);
- if((g_grid[5][j]==2)&&(g_grid[0][j]==3))
- rell(3, j, 4);
- if((g_grid[j][0]==2)&&(g_grid[j][5]==3))
- rell(j, 2, 4);
- if((g_grid[j][5]==2)&&(g_grid[j][0]==3))
- rell(j, 3, 4);
- j++;
- }
- j = 1;
- //4. chequeo
- check_three_num();
- check_diff();
- printf("punto 5");
- //5. caso 2 frente 1 -> 3
- while (j <= 4)
- {
- printf("%i %i \n", g_grid[0][j], g_grid[5][j]);
- if((g_grid[0][j]==2)&&(g_grid[5][j]==1))
- rell(1, j, 3);
- if((g_grid[5][j]==1)&&(g_grid[0][j]==2))
- rell(4, j, 3);
- if((g_grid[j][0]==2)&&(g_grid[j][5]==1))
- rell(j, 1, 3);
- if((g_grid[j][5]==1)&&(g_grid[j][0]==2))
- rell(j, 4, 3);
- j++;
- }
- j = 1;
- }
- int main (int argc, char *argv[])
- {
- g_grid[0][1] = 1; g_grid[0][2] = 0; g_grid[0][3] = 1; g_grid[0][4] = 0;
- g_grid[1][0] = 0; g_grid[1][1] = 0; g_grid[1][2] = 0; g_grid[1][3] = 0; g_grid[1][4] = 0; g_grid[1][5] = 0;
- g_grid[2][0] = 1; g_grid[2][1] = 0; g_grid[2][2] = 0; g_grid[2][3] = 0; g_grid[2][4] = 0; g_grid[2][5] = 2;
- g_grid[3][0] = 0; g_grid[3][1] = 0; g_grid[3][2] = 0; g_grid[3][3] = 0; g_grid[3][4] = 0; g_grid[3][5] = 0;
- g_grid[4][0] = 2; g_grid[4][1] = 0; g_grid[4][2] = 0; g_grid[4][3] = 0; g_grid[4][4] = 0; g_grid[4][5] = 1;
- g_grid[5][1] = 2; g_grid[5][2] = 0; g_grid[5][3] = 2; g_grid[5][4] = 0;
- solver();
- printf ("%i %i %i %i \n", g_grid[1][1], g_grid[1][2], g_grid[1][3], g_grid[1][4]);
- printf ("%i %i %i %i \n", g_grid[2][1], g_grid[2][2], g_grid[2][3], g_grid[2][4]);
- printf ("%i %i %i %i \n", g_grid[3][1], g_grid[3][2], g_grid[3][3], g_grid[3][4]);
- printf ("%i %i %i %i \n", g_grid[4][1], g_grid[4][2], g_grid[4][3], g_grid[4][4]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement