From: Jack Kinsey Date: Tue, 10 Dec 2019 16:39:44 +0000 (-0500) Subject: Add untested day10pt1 X-Git-Url: http://git.jkinsey.net/?p=adventofcode2019.git;a=commitdiff_plain;h=3abd704601d32cd69d62242e8c37c186a732a9c7 Add untested day10pt1 --- diff --git a/src/adventofcode2019/core.clj b/src/adventofcode2019/core.clj index 6d53fd5..ef36fa8 100644 --- a/src/adventofcode2019/core.clj +++ b/src/adventofcode2019/core.clj @@ -1,7 +1,7 @@ (ns adventofcode2019.core - [:require (adventofcode2019 day01 day02 day03 - day04 day05 day06 - day07 day08 day09)]) + [:require (adventofcode2019 day01 day02 day03 day04 + day05 day06 day07 day08 + day09 day10)]) (defn -main ([] diff --git a/src/adventofcode2019/day10.clj b/src/adventofcode2019/day10.clj new file mode 100644 index 0000000..2ea2fd2 --- /dev/null +++ b/src/adventofcode2019/day10.clj @@ -0,0 +1,28 @@ +(ns adventofcode2019.day10 + [:require [adventofcode2019.lib :refer :all] + [clojure.string :as str] + [clojure.core.match :refer [match]] + [clojure.math.combinatorics :as combo]]) + +(defn day10 [] + (let [input (get-list-from-file (input-file)) + to-points (fn [j l] + (map-indexed (fn [i m] + (if (= \# m) [i j] nil)) l)) + asteroids (->> input + (map-indexed to-points) + (reduce concat) + (filter some?) + (set)) + to-slope (fn [[a-x a-y] [b-x b-y]] + (if (= a-x b-x) + :inf + (rationalize + (/ (- a-y b-y) + (- a-x b-x))))) + find-visible (fn [ast] + (count (set (map (partial to-slope ast) + (disj asteroids ast))))) + visible-count (map #(vector % (find-visible %)) asteroids)] + (part1 (reduce (partial max-key second) visible-count)) + #_(part2)))