aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2022-12-04 07:49:02 -0500
committerClyne Sullivan <clyne@bitgloo.com>2022-12-04 07:49:02 -0500
commit82429ac5d021135da9661c18f123ca5699692c15 (patch)
tree734818c7703e7abe024e4165645a6295fc2121d2
parent6b9ec331ef8c35e19c4ccced554a62157bebed3f (diff)
day4: simplify
-rw-r--r--day4/both.clj23
-rw-r--r--day4/part1.clj12
-rw-r--r--day4/part2.clj12
3 files changed, 23 insertions, 24 deletions
diff --git a/day4/both.clj b/day4/both.clj
new file mode 100644
index 0000000..a59098a
--- /dev/null
+++ b/day4/both.clj
@@ -0,0 +1,23 @@
+(defn part1pred [lst]
+ (or (and (>= (nth lst 0) (nth lst 2))
+ (<= (nth lst 1) (nth lst 3)))
+ (and (>= (nth lst 2) (nth lst 0))
+ (<= (nth lst 3) (nth lst 1)))))
+
+(defn part2pred [lst]
+ (or (and (>= (nth lst 0) (nth lst 2)) (<= (nth lst 0) (nth lst 3)))
+ (and (>= (nth lst 1) (nth lst 2)) (<= (nth lst 1) (nth lst 3)))
+ (and (>= (nth lst 2) (nth lst 0)) (<= (nth lst 2) (nth lst 1)))
+ (and (>= (nth lst 3) (nth lst 0)) (<= (nth lst 3) (nth lst 1)))))
+
+(def count-filtered (comp println count filter))
+
+(def elf-pairs
+ (->> (slurp "input")
+ (#(clojure.string/split % #"[^\d]"))
+ (map read-string)
+ (partition 4)))
+
+(count-filtered part1pred elf-pairs)
+(count-filtered part2pred elf-pairs)
+
diff --git a/day4/part1.clj b/day4/part1.clj
deleted file mode 100644
index 72efa35..0000000
--- a/day4/part1.clj
+++ /dev/null
@@ -1,12 +0,0 @@
-(->> (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
deleted file mode 100644
index d5929d6..0000000
--- a/day4/part2.clj
+++ /dev/null
@@ -1,12 +0,0 @@
-(->> (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)