-
Notifications
You must be signed in to change notification settings - Fork 0
/
01.clj
40 lines (34 loc) · 942 Bytes
/
01.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
(ns advent-of-clojure.2021.01
(:require [advent-of-clojure.util :as util]))
(def test-data
[199 200 208 210 200 207 240 269 260 263])
(def data
(->> (util/read-input-lines 2021 01)
(map #(Integer/parseInt %))))
;; The `:input` and `:output` show example input and output.
;; The values are evaluated but discarded,
;; so they don't affect the Clojure program in any way.
;; I learned the trick from Fred Overflow:
;; https://youtu.be/orFYFwiG1dM
:input 2 [1 2 3 4 5]
:output '((1 2) (2 3) (3 4) (4 5))
:input 3 [1 2 3 4 5]
:output '((1 2 3) (2 3 4) (3 4 5))
(defn group [n numbers]
(partition n 1 numbers))
:input [1 2]
:output true
(defn increasing? [[a b]]
(> b a))
(def part-1
(->> data
(group 2)
(filter increasing?)
count))
(def part-2
(->> data
(group 3)
(map #(apply + %))
(group 2)
(filter increasing?)
count))