Add untested day10pt1
authorJack Kinsey <kinsey_john@bah.com>
Tue, 10 Dec 2019 16:39:44 +0000 (11:39 -0500)
committerJack Kinsey <kinsey_john@bah.com>
Tue, 10 Dec 2019 16:39:44 +0000 (11:39 -0500)
src/adventofcode2019/core.clj
src/adventofcode2019/day10.clj [new file with mode: 0644]

index 6d53fd5c5312d3b06099116bc88d71dc4991a495..ef36fa8b1fbc1e8a9dc160fbd458585d0e4ea3ef 100644 (file)
@@ -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 (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)))