aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022/aocclj/src/aocclj/day04.clj
blob: 5b03eeb7c90f5365d6057ad5deb4e1c035f3cfe0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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))