day4: try cleaning up predicates

master
Clyne 2 years ago
parent 82429ac5d0
commit 23effc4830

@ -1,14 +1,14 @@
(defn within [n b e] (and (>= n b) (<= n e)))
(defn part1pred [lst] (defn part1pred [lst]
(or (and (>= (nth lst 0) (nth lst 2)) (or (and (>= (nth lst 0) (nth lst 2)) (<= (nth lst 1) (nth lst 3)))
(<= (nth lst 1) (nth lst 3))) (and (>= (nth lst 2) (nth lst 0)) (<= (nth lst 3) (nth lst 1)))))
(and (>= (nth lst 2) (nth lst 0))
(<= (nth lst 3) (nth lst 1)))))
(defn part2pred [lst] (defn part2pred [lst]
(or (and (>= (nth lst 0) (nth lst 2)) (<= (nth lst 0) (nth lst 3))) (or (within (nth lst 0) (nth lst 2) (nth lst 3))
(and (>= (nth lst 1) (nth lst 2)) (<= (nth lst 1) (nth lst 3))) (within (nth lst 1) (nth lst 2) (nth lst 3))
(and (>= (nth lst 2) (nth lst 0)) (<= (nth lst 2) (nth lst 1))) (within (nth lst 2) (nth lst 0) (nth lst 1))
(and (>= (nth lst 3) (nth lst 0)) (<= (nth lst 3) (nth lst 1))))) (within (nth lst 3) (nth lst 0) (nth lst 1))))
(def count-filtered (comp println count filter)) (def count-filtered (comp println count filter))

Loading…
Cancel
Save