]> code.bitgloo.com Git - clyne/advent-of-code.git/commitdiff
add day4
authorClyne Sullivan <clyne@bitgloo.com>
Sun, 4 Dec 2022 12:34:02 +0000 (07:34 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Sun, 4 Dec 2022 12:34:02 +0000 (07:34 -0500)
day4/part1.clj [new file with mode: 0644]
day4/part2.clj [new file with mode: 0644]

diff --git a/day4/part1.clj b/day4/part1.clj
new file mode 100644 (file)
index 0000000..72efa35
--- /dev/null
@@ -0,0 +1,12 @@
+(->> (slurp "input")
+    (#(clojure.string/split % #"[^0-9]"))
+    (map read-string)
+    (partition 4)
+    (map
+      #(or (and (>= (first %) (nth % 2))
+                (<= (second %) (nth % 3)))
+           (and (>= (nth % 2) (first %))
+                (<= (nth % 3) (second %)))))
+    (filter true?)
+    count
+    println)
diff --git a/day4/part2.clj b/day4/part2.clj
new file mode 100644 (file)
index 0000000..d5929d6
--- /dev/null
@@ -0,0 +1,12 @@
+(->> (slurp "input")
+    (#(clojure.string/split % #"[^0-9]"))
+    (map read-string)
+    (partition 4)
+    (map
+      #(or (and (>= (first %) (nth % 2)) (<= (first %) (nth % 3)))
+           (and (>= (second %) (nth % 2)) (<= (second %) (nth % 3)))
+           (and (>= (nth % 2) (first %)) (<= (nth % 2) (second %)))
+           (and (>= (nth % 3) (first %)) (<= (nth % 3) (second %)))))
+    (filter true?)
+    count
+    println)