-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04.clj
41 lines (36 loc) · 827 Bytes
/
04.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(ns adventofcode2022.04
(:require [clojure.string :as s]))
(defn betweenInclusive
[x a b]
(and (<= x b)
(>= x a)))
(defn isOverlapping
[[aL aH bL bH]]
(and (<= aL bH)
(>= aH bL)))
(defn isBounding
[[aL aH bL bH]]
(or (and (betweenInclusive aL bL bH)
(betweenInclusive aH bL bH))
(and (betweenInclusive bL aL aH)
(betweenInclusive bH aL aH))))
(defn parseInt
[x]
(Integer/parseInt x))
(defn solve1
[]
(->> (slurp "./04-input.txt")
(s/split-lines)
(map #(s/split % #"[^0-9]"))
(map #(map parseInt %))
(filter isBounding)
count))
(defn solve2
[]
(->> (slurp "./04-input.txt")
(s/split-lines)
(map #(s/split % #"[^0-9]"))
(map #(map parseInt %))
(filter isOverlapping)
count))
(solve2)