Add unchecked day16pt1 (tests green)
[adventofcode2019.git] / src / adventofcode2019 / day16.clj
diff --git a/src/adventofcode2019/day16.clj b/src/adventofcode2019/day16.clj
new file mode 100644 (file)
index 0000000..04d6714
--- /dev/null
@@ -0,0 +1,33 @@
+(ns adventofcode2019.day16
+  [:require [adventofcode2019.lib :refer :all]
+   [clojure.string :as str]])
+
+(defn parse-input [input]
+  (map (comp parse-int str) input))
+
+(defn phase [input]
+  (let [pattern (fn [n]
+                  (->> [0 1 0 -1]
+                       (mapcat (partial repeat n))
+                       (cycle)
+                       (rest)))
+        transform (fn [i n]
+                    (->> (map * input (pattern (inc i)))
+                         (reduce +)
+                         (str)
+                         (last)
+                         (str)
+                         (parse-int)))]
+    (map-indexed transform input)))
+
+(defn result-of [input]
+  (as-> (parse-input input) it
+        (iterate phase it)
+        (nth it 100)
+        (take 8 it)
+        (str/join it)))
+
+(defn day16 []
+  (let [[input] (get-list-from-file (input-file))]
+    (part1 (result-of input))
+    #_(part2)))