aboutsummaryrefslogtreecommitdiff
path: root/day03
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2022-12-03 16:32:03 +0000
committerNat Lasseter <user@4574.co.uk>2022-12-03 16:32:03 +0000
commitc62e6e28ad065948557aea88958631462a42b1ec (patch)
treea02897e40f50c62d75e4bb4f06ea60fbaf851e29 /day03
parent17d5ad4f0b630f2e8363c85182ff3dfdeee6dc52 (diff)
Day 03
Diffstat (limited to 'day03')
-rw-r--r--day03/input300
-rw-r--r--day03/part1.rb19
-rw-r--r--day03/part2.rb15
-rw-r--r--day03/test6
4 files changed, 340 insertions, 0 deletions
diff --git a/day03/input b/day03/input
new file mode 100644
index 0000000..cd857ef
--- /dev/null
+++ b/day03/input
@@ -0,0 +1,300 @@
+jNNBMTNzvTqhQLhQLMQL
+VCwnVRCGHHJTdsLtrdhrGdsq
+wFJZTbRcnJCbpwpFccZCBfBvPzfpgfgzzWvjSzNP
+wDWgDfWNTvwvgFfWfddGldJVprrrVdNlrN
+nLnmLSnmMVJvSrHqdV
+MsmsbLvtzMjFsCPDsfBwwT
+WTqSCqWSWqSgVZqJHpHmHrhMMVrRhBnn
+PtLGLGddGGMCpprM
+jFvLPPlLjvfjjffsclvPqzzJWTbqNSWZsbSTDzCW
+lLSSrfmddlNpnmLdfSPddDdbZQTZgZjbZgjcQZHQPjQgZP
+MJMnhzBJVJwvGsMRhRhTsHTjZjHFctbtHZcgZj
+vzvBWGJMVGwWGGhGqVBnGzVGDfCDmrqNfrrLSdpSfLSpNmNC
+qGWLgfbWhqpLgZbJvTRWJTvMWRslMv
+FQwPwNPCVFQQdNcFHNcwwsvslRDRTMDMsVTGJGtRTs
+wQHnwnQFPNPdjnnPjhphGqBrfpBBBfZf
+mpVpmtPhVtPBLLbQTJpBLZ
+vzFMlMzvvRZMTbJQJQbf
+srqzvRRqdvzFFrDnvqldFVtwCVCHWNqJHNNcHchCPt
+CQJJLZCJLqNMMDDgGLVV
+RfRFFszTtzbWTFnRtFrRrWvN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day03/part1.rb
@@ -0,0 +1,19 @@
+def priority(ch)
+ if ch >= ?a && ch <= ?z
+ ch.ord - 96
+ elsif ch >= ?A && ch <= ?Z
+ ch.ord - 64 + 26
+ end
+end
+
+backpacks = $stdin.readlines.map do |line|
+ line = line.strip
+ half = line.length / 2
+ [line[0...half].chars, line[half..-1].chars]
+end
+
+commons = backpacks.map do |f, s|
+ (f & s)[0]
+end
+
+puts commons.map{|ch|priority(ch)}.sum
diff --git a/day03/part2.rb b/day03/part2.rb
new file mode 100644
index 0000000..baaecb9
--- /dev/null
+++ b/day03/part2.rb
@@ -0,0 +1,15 @@
+def priority(ch)
+ if ch >= ?a && ch <= ?z
+ ch.ord - 96
+ elsif ch >= ?A && ch <= ?Z
+ ch.ord - 64 + 26
+ end
+end
+
+backpacks = $stdin.readlines.map(&:strip).map(&:chars)
+
+commons = backpacks.each_slice(3).map do |backpacks|
+ backpacks.inject(:&)[0]
+end
+
+puts commons.map{|ch|priority(ch)}.sum
diff --git a/day03/test b/day03/test
new file mode 100644
index 0000000..f17e726
--- /dev/null
+++ b/day03/test
@@ -0,0 +1,6 @@
+vJrwpWtwJgWrhcsFMMfFFhFp
+jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
+PmmdzqPrVvPwwTWBwg
+wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
+ttgJtRGJQctTZtZT
+CrZsJsPPZsGzwwsLwLmpwMDw