From: Jack Kinsey Date: Fri, 20 Dec 2019 04:32:58 +0000 (-0500) Subject: Add broken day16pt2 X-Git-Url: http://git.jkinsey.net/?a=commitdiff_plain;ds=sidebyside;h=3e681c731e0ca1e70e8c3a0e3dddfc2f2c442ed0;p=adventofcode2019.git Add broken day16pt2 While the implementation is (probably) technically correct, it's not efficient enough. Clearly something is going on here with optimization. --- diff --git a/src/adventofcode2019/day16.clj b/src/adventofcode2019/day16.clj index 04d6714..0e4bc6e 100644 --- a/src/adventofcode2019/day16.clj +++ b/src/adventofcode2019/day16.clj @@ -20,14 +20,26 @@ (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)))) diff --git a/test/adventofcode2019/day16_test.clj b/test/adventofcode2019/day16_test.clj index b39b920..666b16d 100644 --- a/test/adventofcode2019/day16_test.clj +++ b/test/adventofcode2019/day16_test.clj @@ -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"))))