From 057afdc268f82a4c908f224dfc7c062894d5ee7d Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Thu, 3 Dec 2020 01:27:16 -0500 Subject: Solve day 3 part 1 --- 2020/day03.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 2020/day03.c 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 +#include +#include +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); +} -- cgit 1.4.1