Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2017
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.42 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int sumAdj(int [][201], int, int);
  4.  
  5. int main(){
  6.     int x, i;
  7.     int arr[201][201]={{0}};
  8.     int success=0, count=1;
  9.  
  10.     arr[100][100]=1;
  11.  
  12.     for(x=1; x<100 && !success; x++){
  13.         for(i=0; i<x*2 && !success; i++){
  14.              arr[100+x-1-i][100+x]=sumAdj(arr, 100+x-1-i, 100+x);
  15.              success = (arr[100+x-1-i][100+x]> 312051);
  16.             count++;
  17.             printf("%d\n", arr[100+x-1-i][100+x]);
  18.         }
  19.            
  20.         for(i=0; i<x*2 && !success ; i++){
  21.             arr[100-x][100+x-i-1] = sumAdj(arr, 100-x, 100+x-i-1);
  22.             success = (arr[100-x][100+x-i-1] >312051);
  23.             count++;
  24.  
  25.             printf("%d\n", arr[100-x][100+x-i-1]);
  26.         }
  27.  
  28.         for(i=0; i<x*2 && !success; i++){
  29.             arr[100-x+i+1][100-x]=sumAdj(arr, 100-x+i+1, 100-x);
  30.             success = (arr[100-x+i+1][100-x] >312051);
  31.             count++;
  32.  
  33.             printf("%d\n", arr[100-x+i+1][100-x]);
  34.         }
  35.         for(i=0; i<x*2 &&!success; i++){
  36.             arr[100+x][100-x+1+i] = sumAdj(arr, 100+x, 100-x+1+i);
  37.             success = (arr[100+x][100-x+1+i] >312051);
  38.             count++;
  39.             printf("%d\n", arr[100+x][100-x+1+i]);
  40.         }
  41.    
  42.     }
  43.  
  44.     printf("count : %d, succ: %d\n", count, success);
  45.     return 0;
  46. }
  47.  
  48. int sumAdj(int arr[][201], int i, int j){
  49.     printf("%d %d %d\n%d %d %d\n%d %d %d\n", arr[i-1][j-1], arr[i-1][j], arr[i-1][j+1],
  50.                          arr[i][j-1], arr[i][j], arr[i][j+1],
  51.                          arr[i+1][j-1], arr[i+1][j], arr[i+1][j+1]);
  52.  
  53.     return arr[i+1][j] + arr[i-1][j] +arr[i+1][j+1]+arr[i+1][j-1]
  54.             +arr[i][j+1]+arr[i][j-1] +arr[i-1][j-1]+arr[i-1][j+1];
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement