Add untested day10pt1
[adventofcode2019.git] / src / adventofcode2019 / day10.clj
diff --git a/src/adventofcode2019/day10.clj b/src/adventofcode2019/day10.clj
new file mode 100644 (file)
index 0000000..2ea2fd2
--- /dev/null
@@ -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)))