Advertisement
Guest User

Untitled

a guest
Feb 16th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3.  
  4. int g_grid[6][6];
  5.  
  6.  
  7. //relleno campo
  8.  
  9. void rell (int i, int j, int value)
  10. {
  11. printf("%i\n", value);
  12. g_grid[i][j]=value;
  13. }
  14.  
  15. //rellenar una columna entera
  16.  
  17. void rell_grid_1 (int check, int j, int com)
  18. {
  19. if(check == 1)
  20. {
  21. g_grid[1][j] = com;
  22. g_grid[2][j] = com +1;
  23. g_grid[3][j] = com +2;
  24. g_grid[4][j] = com +3;
  25. }
  26. else if (check == 2)
  27. {
  28. g_grid[1][j] = com;
  29. g_grid[2][j] = com -1;
  30. g_grid[3][j] = com -2;
  31. g_grid[4][j] = com -3;
  32. }
  33. else if (check == 3)
  34. {
  35. g_grid[j][1] = com;
  36. g_grid[j][1] = com +1;
  37. g_grid[j][1] = com +2;
  38. g_grid[j][1] = com +3;
  39. }
  40. else if (check == 4)
  41. {
  42. g_grid[j][1] = com;
  43. g_grid[j][2] = com -1;
  44. g_grid[j][3] = com -2;
  45. g_grid[j][4] = com -3;
  46. }
  47. }
  48.  
  49. //chequeo numero iguales
  50.  
  51. void check_rep_num (int case_, int value_)
  52. {
  53. int fil;
  54. int col;
  55. int i;
  56.  
  57. fil = 0;
  58. col = 0;
  59. i=1;
  60.  
  61. while (i<=4)
  62. {
  63. if(!((g_grid[1][i] == value_)||(g_grid[2][i]==value_)||(g_grid[3][i]==value_)||(g_grid[4][i]==value_)))
  64. col = i;
  65.  
  66. if(!((g_grid[i][1]== value_)||(g_grid[i][2]==value_)||(g_grid[i][3]==value_)||(g_grid[i][4]==value_)))
  67. fil = i;
  68.  
  69. //printf("%i %i %i %i\n", g_grid[i][1], g_grid[i][2], g_grid[i][3], g_grid[i][4]);
  70. i++;
  71.  
  72. }
  73.  
  74. //printf("%i %i \n", fil,col);
  75. g_grid[fil][col]=value_;
  76.  
  77. }
  78.  
  79. //chequeo numeros distintos
  80.  
  81. void check_rell_fil_col (int fc, int value_fc , int value_)
  82. {
  83.  
  84. int i;
  85.  
  86. i = 1;
  87. if (fc == 1)
  88. {
  89.  
  90. while (i<=4)
  91. {
  92. if(g_grid[value_fc][i] == 0)
  93. break;
  94.  
  95. //printf("%i %i %i %i\n", g_grid[i][1], g_grid[i][2], g_grid[i][3], g_grid[i][4]);
  96. i++;
  97. }
  98.  
  99. printf("%i %i \n", fc,i);
  100. g_grid[value_fc][i]=value_;
  101.  
  102. }else if (fc == 2)
  103. {
  104. while (i<=4)
  105. {
  106. if(g_grid[i][value_fc] == 0)
  107. break;
  108.  
  109. //printf("%i %i %i %i\n", g_grid[i][1], g_grid[i][2], g_grid[i][3], g_grid[i][4]);
  110. i++;
  111. }
  112.  
  113. printf("%i %i \n", fc,i);
  114. g_grid[i][value_fc]=value_;
  115. }
  116. }
  117.  
  118. // check_three
  119.  
  120. void check_three_num (void)
  121. {
  122. int count = 0;
  123. int aux = 0;
  124. int i = 1;
  125. int j = 1;
  126.  
  127. while (i<=4)
  128. {
  129. while (j<=4)
  130. {
  131. //printf("%i %i %i \n", g_grid[i][j], i, j);
  132.  
  133. if (g_grid[i][j]==4)
  134. count++;
  135.  
  136. j++;
  137. }
  138. j=1;
  139. i++;
  140. }
  141.  
  142. //printf("%i\n", count);
  143. if (count==3){
  144. check_rep_num(1, 4);
  145. }
  146.  
  147. }
  148.  
  149. // check diff
  150.  
  151. void check_diff (void)
  152. {
  153.  
  154. int count = 0;
  155. int aux = 0;
  156. int i = 1;
  157. int j = 1;
  158.  
  159. //filas
  160.  
  161. while(j<=4)
  162. {
  163. while (i<=4)
  164. {
  165. if (g_grid[j][i]!=0)
  166. {
  167. count++;
  168. aux = aux + g_grid[j][i];
  169. }
  170.  
  171. i++;
  172. }
  173.  
  174. if (count==3){
  175. printf("%i %i \n", j, aux);
  176. //check_rep_num(2, 10-aux);
  177. check_rell_fil_col(1, j, 10-aux);
  178. }
  179.  
  180. count = 0;
  181. aux = 0;
  182. i = 1;
  183. j++;
  184. }
  185.  
  186. count = 0;
  187. aux = 0;
  188. i = 1;
  189. j = 1;
  190.  
  191. //columnas
  192. while(j<=4)
  193. {
  194. while (i<=4)
  195. {
  196. if (g_grid[i][j]!=0)
  197. {
  198. count++;
  199. aux = aux + g_grid[i][j];
  200. }
  201.  
  202. i++;
  203. }
  204.  
  205. if (count==3){
  206. //printf("%i %i \n", j, aux);
  207. //check_rep_num(2, 10-aux);
  208. check_rell_fil_col(2, j, 10-aux);
  209. }
  210.  
  211. count = 0;
  212. aux = 0;
  213. i = 1;
  214. j++;
  215. }
  216.  
  217. }
  218.  
  219.  
  220. void solver (void)
  221. {
  222.  
  223. //1. caso 4 frente 1
  224.  
  225. int j = 1;
  226. int i = 1;
  227. int count = 0;
  228. int count_1 = 0;
  229. int aux = 0;
  230.  
  231. while (j <= 4)
  232. {
  233. if((g_grid[0][j]==4)&&(g_grid[5][j]==1))
  234. rell_grid_1 (1, j, 1);
  235.  
  236. if((g_grid[5][j]==4)&&(g_grid[0][j]==1))
  237. rell_grid_1 (2, j, 4);
  238.  
  239. if((g_grid[j][0]==4)&&(g_grid[j][5]==1))
  240. rell_grid_1 (3, j, 1);
  241.  
  242. if((g_grid[j][5]==4)&&(g_grid[j][0]==1))
  243. rell_grid_1 (4, j, 4);
  244.  
  245. j++;
  246. }
  247.  
  248. j = 1;
  249.  
  250. //2. caso 1 - rellenar "4"
  251.  
  252. while (j <= 4)
  253. {
  254. if(g_grid[0][j]==1)
  255. rell(1, j,4);
  256.  
  257. if(g_grid[5][j]==1)
  258. rell(4, j,4);
  259.  
  260. if(g_grid[j][0]==1)
  261. rell(j, 1,4);
  262.  
  263. if(g_grid[j][5]==1)
  264. rell(j, 4,4);
  265.  
  266. j++;
  267. }
  268.  
  269. j = 1;
  270.  
  271. //3. caso 2 frente 3 -> poner 4 en la tercera posicion
  272.  
  273. while (j <= 4)
  274. {
  275. if((g_grid[0][j]==2)&&(g_grid[5][j]==3))
  276. rell(2, j, 4);
  277.  
  278. if((g_grid[5][j]==2)&&(g_grid[0][j]==3))
  279. rell(3, j, 4);
  280.  
  281. if((g_grid[j][0]==2)&&(g_grid[j][5]==3))
  282. rell(j, 2, 4);
  283.  
  284. if((g_grid[j][5]==2)&&(g_grid[j][0]==3))
  285. rell(j, 3, 4);
  286.  
  287. j++;
  288. }
  289.  
  290. j = 1;
  291.  
  292. //4. chequeo
  293.  
  294. check_three_num();
  295. check_diff();
  296.  
  297. printf("punto 5");
  298.  
  299. //5. caso 2 frente 1 -> 3
  300.  
  301. while (j <= 4)
  302. {
  303. printf("%i %i \n", g_grid[0][j], g_grid[5][j]);
  304. if((g_grid[0][j]==2)&&(g_grid[5][j]==1))
  305. rell(1, j, 3);
  306.  
  307. if((g_grid[5][j]==1)&&(g_grid[0][j]==2))
  308. rell(4, j, 3);
  309.  
  310. if((g_grid[j][0]==2)&&(g_grid[j][5]==1))
  311. rell(j, 1, 3);
  312.  
  313. if((g_grid[j][5]==1)&&(g_grid[j][0]==2))
  314. rell(j, 4, 3);
  315.  
  316. j++;
  317. }
  318.  
  319. j = 1;
  320.  
  321. }
  322.  
  323. int main (int argc, char *argv[])
  324. {
  325.  
  326. g_grid[0][1] = 1; g_grid[0][2] = 0; g_grid[0][3] = 1; g_grid[0][4] = 0;
  327. 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;
  328. 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;
  329. 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;
  330. 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;
  331. g_grid[5][1] = 2; g_grid[5][2] = 0; g_grid[5][3] = 2; g_grid[5][4] = 0;
  332.  
  333.  
  334. solver();
  335.  
  336. printf ("%i %i %i %i \n", g_grid[1][1], g_grid[1][2], g_grid[1][3], g_grid[1][4]);
  337. printf ("%i %i %i %i \n", g_grid[2][1], g_grid[2][2], g_grid[2][3], g_grid[2][4]);
  338. printf ("%i %i %i %i \n", g_grid[3][1], g_grid[3][2], g_grid[3][3], g_grid[3][4]);
  339. printf ("%i %i %i %i \n", g_grid[4][1], g_grid[4][2], g_grid[4][3], g_grid[4][4]);
  340.  
  341. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement