From 3e681c731e0ca1e70e8c3a0e3dddfc2f2c442ed0 Mon Sep 17 00:00:00 2001 From: Jack Kinsey Date: Thu, 19 Dec 2019 23:32:58 -0500 Subject: [PATCH] Add broken day16pt2 While the implementation is (probably) technically correct, it's not efficient enough. Clearly something is going on here with optimization. --- src/adventofcode2019/day16.clj | 26 +++++++++++++++++++------- test/adventofcode2019/day16_test.clj | 7 ++++++- 2 files changed, 25 insertions(+), 8 deletions(-) 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")))) -- 2.38.5