Add unchecked day16pt1 (tests green)
authorJack Kinsey <kinsey_john@bah.com>
Thu, 19 Dec 2019 18:06:15 +0000 (13:06 -0500)
committerJack Kinsey <kinsey_john@bah.com>
Thu, 19 Dec 2019 18:06:15 +0000 (13:06 -0500)
src/adventofcode2019/core.clj
src/adventofcode2019/day16.clj [new file with mode: 0644]
test/adventofcode2019/day16_test.clj [new file with mode: 0644]

index 3e6794e99f47314795111e282ea4e6061524ba0d..6ab7f7ce70822590a9c60fdd6789466210f6c0e2 100644 (file)
@@ -1,7 +1,8 @@
 (ns adventofcode2019.core
     [:require (adventofcode2019 day01 day02 day03 day04 day05 
                                 day06 day07 day08 day09 day10 
-                                day11 day12 day13 day14)])
+                                day11 day12 day13 day14      
+                                day16)])
 
 (defn -main 
   ([]
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)))
diff --git a/test/adventofcode2019/day16_test.clj b/test/adventofcode2019/day16_test.clj
new file mode 100644 (file)
index 0000000..b39b920
--- /dev/null
@@ -0,0 +1,8 @@
+(ns adventofcode2019.day16-test
+  (:require [clojure.test :refer :all]
+            [adventofcode2019.day16 :refer :all]))
+
+(deftest examples
+  (is (= "24176176" (result-of "80871224585914546619083218645595")))
+  (is (= "73745418" (result-of "19617804207202209144916044189917")))
+  (is (= "52432133" (result-of "69317163492948606335995924319873"))))