Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- // Starting in the top left corner of a 22 grid, there are 6 routes (without backtracking) to the bottom right corner.
- // How many routes are there through a 2020 grid?
- #define GRID_SIZE 20
- int traverse(int x, int y);
- int main() {
- printf("%d", traverse(0, 0));
- return 1;
- }
- int traverse(int x, int y) {
- int i = 0;
- if(x < GRID_SIZE) {
- i += traverse(x + 1, y);
- }
- if(y < GRID_SIZE) {
- i += traverse(x, y + 1);
- }
- if(x == GRID_SIZE && y == GRID_SIZE) {
- return 1;
- }
- return i;
- }
Add Comment
Please, Sign In to add comment