X-Git-Url: http://git.jkinsey.net/?p=adventofcode2019.git;a=blobdiff_plain;f=src%2Fadventofcode2019%2Fday10.clj;fp=src%2Fadventofcode2019%2Fday10.clj;h=2ea2fd23734afd2dc03b28c862b688aa0f8e4780;hp=0000000000000000000000000000000000000000;hb=3abd704601d32cd69d62242e8c37c186a732a9c7;hpb=b973b0f57305f0388fd9a8be124991161a19d452 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)))