Add untested day10pt1
[adventofcode2019.git] / src / adventofcode2019 / day10.clj
CommitLineData
3abd7046
JK
1(ns adventofcode2019.day10
2 [:require [adventofcode2019.lib :refer :all]
3 [clojure.string :as str]
4 [clojure.core.match :refer [match]]
5 [clojure.math.combinatorics :as combo]])
6
7(defn day10 []
8 (let [input (get-list-from-file (input-file))
9 to-points (fn [j l]
10 (map-indexed (fn [i m]
11 (if (= \# m) [i j] nil)) l))
12 asteroids (->> input
13 (map-indexed to-points)
14 (reduce concat)
15 (filter some?)
16 (set))
17 to-slope (fn [[a-x a-y] [b-x b-y]]
18 (if (= a-x b-x)
19 :inf
20 (rationalize
21 (/ (- a-y b-y)
22 (- a-x b-x)))))
23 find-visible (fn [ast]
24 (count (set (map (partial to-slope ast)
25 (disj asteroids ast)))))
26 visible-count (map #(vector % (find-visible %)) asteroids)]
27 (part1 (reduce (partial max-key second) visible-count))
28 #_(part2)))