summary refs log tree commit diff homepage
path: root/2023
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2023-12-01 11:03:36 -0500
committerJune McEnroe <june@causal.agency>2023-12-01 11:03:36 -0500
commitbc46bac92724c8b6055eb5b7274d36a5bca65a2a (patch)
tree679f24faf0393024f21872f4209791d076dff85f /2023
parentSolve day 1 part 1 (diff)
downloadaoc-bc46bac92724c8b6055eb5b7274d36a5bca65a2a.tar.gz
aoc-bc46bac92724c8b6055eb5b7274d36a5bca65a2a.zip
Solve day 1 part 2
Diffstat (limited to '2023')
-rw-r--r--2023/day01.awk34
1 files changed, 33 insertions, 1 deletions
diff --git a/2023/day01.awk b/2023/day01.awk
index 3127556..519b414 100644
--- a/2023/day01.awk
+++ b/2023/day01.awk
@@ -1,7 +1,39 @@
 {
-	gsub("[^[:digit:]]", "");
+	first = 0;
+	for (i = 0; i <= length; i++) {
+		digit = 0;
+		s = substr($0, i);
+		if (s ~ /^one/) {
+			digit = 1;
+		} else if (s ~ /^two/) {
+			digit = 2;
+		} else if (s ~ /^three/) {
+			digit = 3;
+		} else if (s ~ /^four/) {
+			digit = 4;
+		} else if (s ~ /^five/) {
+			digit = 5;
+		} else if (s ~ /^six/) {
+			digit = 6;
+		} else if (s ~ /^seven/) {
+			digit = 7;
+		} else if (s ~ /^eight/) {
+			digit = 8;
+		} else if (s ~ /^nine/) {
+			digit = 9;
+		} else if (s ~ /^[[:digit:]]/) {
+			digit = substr(s, 1, 1);
+		}
+		if (digit) {
+			if (!first) first = digit;
+			last = digit;
+		}
+	}
+	gsub(/[^[:digit:]]/, "");
 	part1 += substr($0, 1, 1) substr($0, length, 1);
+	part2 += first last;
 }
 END {
 	print part1;
+	print part2;
 }
0a040dd154a8c3b9075baadcec81884748&follow=1'>Use scheme.h in fbatt and fbclockJune McEnroe 2018-08-20Generate scheme.hJune McEnroe 2018-08-20Add dependencies on gfx.hJune McEnroe 2018-08-18Add Blondie — Heart of GlassJune McEnroe Why didn't I know about this song? I love it. 2018-08-18Set FCEDIT=$EDITORJune McEnroe 2018-08-18Only post commits with bodies to MastodonJune McEnroe 2018-08-18Run tf/cfg link script with /bin/shJune McEnroe 2018-08-18Run {,s,t}up with /bin/shJune McEnroe 2018-08-18Use whence instead of typeJune McEnroe type is an alias for whence -v and is more for human consumption. 2018-08-18Cut off path components until right prompt fitsJune McEnroe Keeps paths valid (from somehwere) rather than abrupt truncation. 2018-08-17Add "private" alias to source encrypted fileJune McEnroe Why is there no easy way to *edit* an encrypted file? 2018-08-17Add vim mapping to add a #includeJune McEnroe