Add broken day16pt2
authorJack Kinsey <j.jameskinsey@gmail.com>
Fri, 20 Dec 2019 04:32:58 +0000 (23:32 -0500)
committerJack Kinsey <j.jameskinsey@gmail.com>
Fri, 20 Dec 2019 04:32:58 +0000 (23:32 -0500)
While the implementation is (probably) technically correct, it's not
efficient enough. Clearly something is going on here with optimization.

src/adventofcode2019/day16.clj
test/adventofcode2019/day16_test.clj

index 04d6714636da5e79938305e86fead68c91998a86..0e4bc6e1510edb6a20da852e744ce3ba103f2c9a 100644 (file)
                          (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 result-of 
+  ([input]
+    (result-of 0 input))
+  ([offset input]
+    (as-> (parse-input input) it
+          (iterate phase it)
+          (nth it 100)
+          (drop offset it)
+          (take 8 it)
+          (str/join it))))
+
+(defn fft [input]
+  (->> (repeat 10000 input)
+       (str/join)
+       (result-of (->> input
+                       (take 7)
+                       (str/join)
+                       (parse-int)))))
 
 (defn day16 []
   (let [[input] (get-list-from-file (input-file))]
     (part1 (result-of input))
-    #_(part2)))
+    (part2 (fft input))))
index b39b9202c23eabee6fa35a3a7ad5f683f21c7934..666b16d80e4981308eafe11a3dbac061b9634e92 100644 (file)
@@ -2,7 +2,12 @@
   (:require [clojure.test :refer :all]
             [adventofcode2019.day16 :refer :all]))
 
-(deftest examples
+(deftest examples-part1
   (is (= "24176176" (result-of "80871224585914546619083218645595")))
   (is (= "73745418" (result-of "19617804207202209144916044189917")))
   (is (= "52432133" (result-of "69317163492948606335995924319873"))))
+
+(deftest examples-part2
+  #_(is (= "84462026" (fft "03036732577212944063491565474664")))
+  #_(is (= "78725270" (fft "02935109699940807407585447034323")))
+  #_(is (= "53553731" (fft "03081770884921959731165446850517"))))