diff options
Diffstat (limited to '')
-rw-r--r-- | 2020/day03.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/2020/day03.c b/2020/day03.c new file mode 100644 index 0000000..cd792a7 --- /dev/null +++ b/2020/day03.c @@ -0,0 +1,16 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +int main(void) { + char grid[512][32]; + int h = 0; + while (EOF != scanf("%s\n", grid[h])) { + h++; + } + int w = strlen(grid[0]); + int trees = 0; + for (int x = 0, y = 0; y < h; x += 3, y += 1) { + trees += grid[y][x%w] == '#'; + } + printf("%d\n", trees); +} |