From: Jack Kinsey Date: Thu, 19 Dec 2019 18:06:15 +0000 (-0500) Subject: Add unchecked day16pt1 (tests green) X-Git-Url: http://git.jkinsey.net/?p=adventofcode2019.git;a=commitdiff_plain;h=21ab31d9418c308ae58d73141184be8b42a11ab8 Add unchecked day16pt1 (tests green) --- diff --git a/src/adventofcode2019/core.clj b/src/adventofcode2019/core.clj index 3e6794e..6ab7f7c 100644 --- a/src/adventofcode2019/core.clj +++ b/src/adventofcode2019/core.clj @@ -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 index 0000000..04d6714 --- /dev/null +++ b/src/adventofcode2019/day16.clj @@ -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 index 0000000..b39b920 --- /dev/null +++ b/test/adventofcode2019/day16_test.clj @@ -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"))))