about summary refs log tree commit diff
path: root/day02.clj
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2020-12-03 15:25:35 +0100
committerLeah Neukirchen <leah@vuxu.org>2020-12-03 15:25:35 +0100
commita804cd7bdf6cf1557cca4656eeca678925059358 (patch)
tree0ca179dddcb2c9a4d2a38c1a74c3c92b9161b1db /day02.clj
parent4fcb892b97f7bbdba4c2a873e4493a00722ef40e (diff)
downloadadventofcode2020-a804cd7bdf6cf1557cca4656eeca678925059358.tar.gz
adventofcode2020-a804cd7bdf6cf1557cca4656eeca678925059358.tar.xz
adventofcode2020-a804cd7bdf6cf1557cca4656eeca678925059358.zip
day02
Diffstat (limited to 'day02.clj')
-rw-r--r--day02.clj17
1 files changed, 17 insertions, 0 deletions
diff --git a/day02.clj b/day02.clj
new file mode 100644
index 0000000..e6a1a5b
--- /dev/null
+++ b/day02.clj
@@ -0,0 +1,17 @@
+(def data
+  (->> (slurp "day02")
+       (clojure.string/split-lines)
+       (map #(re-matches #"(\d+)-(\d+) (.): (.*)" %))
+       (map (fn [[_ a b c d]]
+              [(Integer/parseInt a) (Integer/parseInt b) (first c) d]))))
+
+(defn valid-1? [[a b c d]]
+  (<= a (count (filter #{c} d)) b))
+
+(count (filter valid-1? data)) ; => 586
+
+(defn valid-2? [[a b c d]]
+  (not= (= c (nth d (- a 1)))
+        (= c (nth d (- b 1)))))
+
+(count (filter valid-2? data)) ; => 352