summary refs log tree commit diff homepage
path: root/2023
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--2023/day03.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/2023/day03.c b/2023/day03.c
new file mode 100644
index 0000000..eba3382
--- /dev/null
+++ b/2023/day03.c
@@ -0,0 +1,24 @@
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+int main(void) {
+	int sum = 0;
+	char g[150][150];
+	int h = 0;
+	while (gets(g[h++]));
+	int w = strlen(g[--h-1]);
+	for (int y = 0; y < h; ++y)
+	for (int x = 0; x < w; ++x) {
+		if (g[y][x] == '.' || isdigit(g[y][x])) continue;
+		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);
+			while (isdigit(*p)) *p++ = '.';
+		}
+	}
+	printf("%d\n", sum);
+}
bc356be3cc6726101bd5879e16180bd04064&follow=1'>Remove gfxx reverse optionJune McEnroe 2018-02-04Fix gfxx draw stop conditionJune McEnroe 2018-02-04Reuse CGColorSpace and CGDataProvider in gfcocoaJune McEnroe 2018-02-04Mark mac target phonyJune McEnroe 2018-02-04Set up Makefile for gfxx-cocoa or gfxx-fbJune McEnroe 2018-02-04Avoid doing excessive work in gfxxJune McEnroe 2018-02-04Handle window resizing in gfcocoaJune McEnroe 2018-02-04Set cinoptionsJune McEnroe 2018-02-04Tweak colorscheme moreJune McEnroe 2018-02-04Color MatchParen DarkYellowJune McEnroe 2018-02-04Add palette sampling to gfxxJune McEnroe 2018-02-04Add 4-bit RGB to gfxxJune McEnroe 2018-02-04Add Quit menu item to gfcocoaJune McEnroe 2018-02-04Switch back to sane Objective-C styleJune McEnroe 2018-02-04Quit gfcocoa when window closesJune McEnroe 2018-02-03Apparently this is how people write Objective-CJune McEnroe