about summary refs log tree commit diff
path: root/day10.clj
blob: 255ba27f1a396785b99ab0f467e63018bb9ad2c0 (plain) (blame)
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
(def data
  (->> (slurp "day10")
       (clojure.string/split-lines)
       (map read-string)
       vec))

(def diff
  (->> data
       (#(cons 0 %))
       (#(cons (+ 3 (reduce max %)) %))
       sort
       (#(map - (rest %) %))))

(->> diff
     frequencies
     (#(map % [1 3]))
     (apply *)) ; => 1820

(->> diff
     (partition-by identity)
     (filter #(= (first %) 1))
     (map count)
     (map #(inc (* (dec %) (/ % 2))))   ; http://oeis.org/A000124
     (apply *)) ; => 3454189699072N

;; => (1 3 1 1 1 3 1 1 3 1 3 3)
;;      1     4      2    1
;;
;; => (1 1 1 1 3 1 1 1 1 3 3 1 1 1 3 1 1 3 3 1 1 1 1 3 1 3 3 1 1 1 1 3)
;;        7         7          4      2         7      1        7
;; 19208: 2 2 2 7 7 7 7