summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--2023/day03.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/2023/day03.c b/2023/day03.c
index eba3382..4b91695 100644
--- a/2023/day03.c
+++ b/2023/day03.c
@@ -3,7 +3,7 @@
 #include <stdlib.h>
 #include <string.h>
 int main(void) {
-	int sum = 0;
+	int sum = 0, sum2 = 0;
 	char g[150][150];
 	int h = 0;
 	while (gets(g[h++]));
@@ -11,14 +11,19 @@ int main(void) {
 	for (int y = 0; y < h; ++y)
 	for (int x = 0; x < w; ++x) {
 		if (g[y][x] == '.' || isdigit(g[y][x])) continue;
+		int n = 0, r = 1;
 		for (int i = -1; i <= +1; ++i)
 		for (int j = -1; j <= +1; ++j) {
 			char *p = &g[y+i][x+j];
 			if (!isdigit(*p)) continue;
 			while (p > g[y+i] && isdigit(p[-1])) p--;
 			sum += atoi(p);
+			r *= atoi(p);
+			n++;
 			while (isdigit(*p)) *p++ = '.';
 		}
+		if (n == 2) sum2 += r;
 	}
 	printf("%d\n", sum);
+	printf("%d\n", sum2);
 }
0bfd5cb5e9358aa&follow=1'>Render tag index in HTMLJune McEnroe 2021-01-12Add htagml -xJune McEnroe 2021-01-12Prevent matching the same tag twiceJune McEnroe 2021-01-12Process htagml file line by lineJune McEnroe 2021-01-12Split fields by tab onlyJune McEnroe 2021-01-12List both Makefile and html.sh under README.7June McEnroe 2021-01-12Add htagml exampleJune McEnroe 2021-01-12Use mandoc and htagml for bin htmlJune McEnroe 2021-01-12Add htagmlJune McEnroe 2021-01-12Replace causal.agency with a simple mdoc pageJune McEnroe 2021-01-11Publish "Using vi"June McEnroe 2021-01-11Enable diff.colorMovedJune McEnroe 2021-01-10Set less search case-insensitiveJune McEnroe 2021-01-10Set EXINITJune McEnroe 2021-01-09Add c -t flag to print expression typeJune McEnroe 2021-01-05Update taglineJune McEnroe