diff options
author | Oscar Najera <hi@oscarnajera.com> | 2023-02-07 18:48:59 +0100 |
---|---|---|
committer | Oscar Najera <hi@oscarnajera.com> | 2023-02-07 18:48:59 +0100 |
commit | 0b36acbe058a0afb63f2c35ce8cc24fca042e8f3 (patch) | |
tree | e821358f384eb4d5b3a58e8d13bff1cdb094bbda /AoC2022/aocclj/src | |
parent | 99bcf55e2df61cef89cb88213e6feddd88294d47 (diff) | |
download | scratch-0b36acbe058a0afb63f2c35ce8cc24fca042e8f3.tar.gz scratch-0b36acbe058a0afb63f2c35ce8cc24fca042e8f3.tar.bz2 scratch-0b36acbe058a0afb63f2c35ce8cc24fca042e8f3.zip |
day04
Diffstat (limited to 'AoC2022/aocclj/src')
-rw-r--r-- | AoC2022/aocclj/src/aocclj/day04.clj | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/AoC2022/aocclj/src/aocclj/day04.clj b/AoC2022/aocclj/src/aocclj/day04.clj new file mode 100644 index 0000000..5b03eeb --- /dev/null +++ b/AoC2022/aocclj/src/aocclj/day04.clj @@ -0,0 +1,23 @@ +(ns aocclj.day04 + (:require [clojure.string :as str])) + +(defn subinterval [a0 a1 b0 b1] + (and (<= a0 b0) (>= a1 b1))) + +(defn subcontained [a0 a1 b0 b1] + (or (subinterval a0 a1 b0 b1) + (subinterval b0 b1 a0 a1))) + +(defn overlap [a0 a1 b0 b1] + "Test if [b0;b1] overlaps [a0;a1]" + (and (<= a0 b1) (<= b0 a1))) + +(defn solver [func input] + (transduce + (comp + (map #(str/split % #"[,-]")) + (map (partial map parse-long)) + (map #(apply func %)) + (map #(if (true? %) 1 0))) + + + input)) |