Add broken day16pt2
[adventofcode2019.git] / src / adventofcode2019 / day16.clj
CommitLineData
21ab31d9
JK
1(ns adventofcode2019.day16
2 [:require [adventofcode2019.lib :refer :all]
3 [clojure.string :as str]])
4
5(defn parse-input [input]
6 (map (comp parse-int str) input))
7
8(defn phase [input]
9 (let [pattern (fn [n]
10 (->> [0 1 0 -1]
11 (mapcat (partial repeat n))
12 (cycle)
13 (rest)))
14 transform (fn [i n]
15 (->> (map * input (pattern (inc i)))
16 (reduce +)
17 (str)
18 (last)
19 (str)
20 (parse-int)))]
21 (map-indexed transform input)))
22
3e681c73
JK
23(defn result-of
24 ([input]
25 (result-of 0 input))
26 ([offset input]
27 (as-> (parse-input input) it
28 (iterate phase it)
29 (nth it 100)
30 (drop offset it)
31 (take 8 it)
32 (str/join it))))
33
34(defn fft [input]
35 (->> (repeat 10000 input)
36 (str/join)
37 (result-of (->> input
38 (take 7)
39 (str/join)
40 (parse-int)))))
21ab31d9
JK
41
42(defn day16 []
43 (let [[input] (get-list-from-file (input-file))]
44 (part1 (result-of input))
3e681c73 45 (part2 (fft input))))