Guest User

Untitled

a guest
Jun 23rd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. // Starting in the top left corner of a 22 grid, there are 6 routes (without backtracking) to the bottom right corner.
  4.  
  5.  
  6. // How many routes are there through a 2020 grid?
  7. #define GRID_SIZE 20
  8.  
  9. int traverse(int x, int y);
  10.  
  11. int main() {
  12.     printf("%d", traverse(0, 0));
  13.    
  14.     return 1;
  15. }
  16.  
  17. int traverse(int x, int y) {
  18.     int i = 0;
  19.  
  20.     if(x < GRID_SIZE) {
  21.         i += traverse(x + 1, y);
  22.     }
  23.     if(y < GRID_SIZE) {
  24.         i += traverse(x, y + 1);
  25.     }
  26.  
  27.     if(x == GRID_SIZE && y == GRID_SIZE) {
  28.         return 1;
  29.     }
  30.  
  31.     return i;
  32. }
Add Comment
Please, Sign In to add comment