-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathday10.clj
More file actions
26 lines (22 loc) · 721 Bytes
/
Copy pathday10.clj
File metadata and controls
26 lines (22 loc) · 721 Bytes
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
(ns advent-2020-clojure.day10
(:require [clojure.string :as str]))
(defn parse-jolts [input]
(->> (str/split-lines input)
(map #(Integer/parseInt %))
(cons 0)))
(defn part1 [input]
(let [jolts (-> input parse-jolts sort)
{ones 1 threes 3} (->> (map - (rest jolts) jolts)
frequencies)]
(* ones (inc threes))))
(defn paths-from [jolts]
(let [rev (sort-by - jolts)]
(reduce (fn [acc n]
(->> (map + [1 2 3] (repeat n))
(keep #(acc %))
(apply +)
(assoc acc n)))
{(first rev) 1}
(rest rev))))
(defn part2 [input]
(-> (parse-jolts input) paths-from (get 0)))