summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-12-03 01:27:16 -0500
committerJune McEnroe <june@causal.agency>2020-12-03 01:27:16 -0500
commit057afdc268f82a4c908f224dfc7c062894d5ee7d (patch)
tree09ae64d0fe6e602fa3a66fe3326ca3db4a0d5172
parentSolve day 2 part 2 (diff)
downloadaoc-057afdc268f82a4c908f224dfc7c062894d5ee7d.tar.gz
aoc-057afdc268f82a4c908f224dfc7c062894d5ee7d.zip
Solve day 3 part 1
-rw-r--r--2020/day03.c16
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);
+}