woonie

guess the code

Nov 17th, 2011
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. int g[81][11];
  2.  
  3. int tile(int x)
  4. {
  5.     int a;
  6.     for(a=1; a<10 && x<81 && !g[x][10]; a++)
  7.         g[x][a] = 1;
  8.  
  9.     for(a=0; a<9 && x<81 && !g[x][10]; a++)
  10.         g[x][g[x/9*9+a][0]] = g[x][g[x%9+9*a][0]] = g[x][g[x%9/3*3+x/27*27+a/3*9+a%3][0]] = 0;
  11.  
  12.     for(a=0; a<10 && x<81; a++)
  13.         if(g[x][a])
  14.         {
  15.             g[x][0] = a?a:g[x][10];
  16.  
  17.             if(tile(x+1))
  18.                 return printf(x%9?"%d ":"%d \n",g[x][0])|1;
  19.         }
  20.  
  21.     g[x][0] = g[x][10];
  22.     return x>80;
  23. }
  24.  
  25. int main()
  26. {
  27.     int x;
  28.     char c[9];
  29.     for(x=0; x<81 && (x%9 || scanf("%s",c)|1); x++)
  30.         g[80-x][10] = g[80-x][0] = (c[x%9]-48);
  31.  
  32.     return tile(0);
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment