From 23effc48309276caead656b366a8bd915196fef5 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sun, 4 Dec 2022 08:22:52 -0500 Subject: [PATCH] day4: try cleaning up predicates --- day4/both.clj | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/day4/both.clj b/day4/both.clj index a59098a..441ec16 100644 --- a/day4/both.clj +++ b/day4/both.clj @@ -1,14 +1,14 @@ +(defn within [n b e] (and (>= n b) (<= n e))) + (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))))) + (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))))) + (or (within (nth lst 0) (nth lst 2) (nth lst 3)) + (within (nth lst 1) (nth lst 2) (nth lst 3)) + (within (nth lst 2) (nth lst 0) (nth lst 1)) + (within (nth lst 3) (nth lst 0) (nth lst 1)))) (def count-filtered (comp println count filter))