Introduction
Introduction Statistics Contact Development Disclaimer Help
tadd day 3 part 2 - aoc22 - advent of code 2022 solutions
git clone git://src.adamsgaard.dk/aoc22
Log
Files
Refs
README
---
commit 1507978f5cbd50e4aa85be9532a9b0555d5148e5
parent d542900c3f9dd47037e95ba4525cd280933dccec
Author: Anders Damsgaard <[email protected]>
Date: Sat, 3 Dec 2022 11:59:31 +0000
add day 3 part 2
Diffstat:
A 3/aoc3b | 21 +++++++++++++++++++++
M 3/mkfile | 8 ++++++--
2 files changed, 27 insertions(+), 2 deletions(-)
---
diff --git a/3/aoc3b b/3/aoc3b
t@@ -0,0 +1,21 @@
+#!/bin/awk -f
+function val(c) {
+ if (n=index(items, c))
+ sub(c, "_", items)
+ return n
+}
+{
+ items = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ s1=$0
+ getline
+ s2=$0
+ getline
+ s3=$0
+ n1 = length(s1)
+ for (i=1; i<=n1; i++) {
+ c = substr(s1, i, 1)
+ if (index(s2, c) && index(s3, c))
+ sum += val(c)
+ }
+}
+END{ print sum }
diff --git a/3/mkfile b/3/mkfile
t@@ -1,8 +1,13 @@
run:V:
./aoc3 <input
+ ./aoc3b <input
test:V:
# 16 (p), 38 (L), 42 (P), 22 (v), 20 (t), and 19 (s)
# correct sum is 157
./aoc3 <testinput
-
-\ No newline at end of file
+
+test2:V:
+ # group 1 = r, group 2 = Z
+ # sum must be 18+52=70
+ ./aoc3b <testinput
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.