Add broken day12pt2
authorJack Kinsey <kinsey_john@bah.com>
Fri, 20 Dec 2019 23:21:13 +0000 (18:21 -0500)
committerJack Kinsey <kinsey_john@bah.com>
Fri, 20 Dec 2019 23:21:13 +0000 (18:21 -0500)
The values flip and stuff which is maybe tractable

project.clj
src/adventofcode2019/day12.clj

index 7e487cb4dfe94d8076e238ec11ac1536a2708d96..cb2791c1e3cc8909a39ce1927d6943c130993674 100644 (file)
@@ -5,10 +5,11 @@
 ;;          :url "https://www.eclipse.org/legal/epl-2.0/"}
   :dependencies [[org.clojure/clojure "1.10.0"]
                  [org.clojure/core.match "0.3.0"]
-                 [org.clojure/math.combinatorics "0.1.6"]
                  [org.clojure/core.async "0.6.532"]
+                 [org.clojure/math.combinatorics "0.1.6"]
                  [org.clojure/data.priority-map "0.0.10"]
-                 [clojure-lanterna "0.9.4"]]
+                 [clojure-lanterna "0.9.4"]
+                 [aysylu/loom "1.0.2"]]
   :main ^:skip-aot adventofcode2019.core
   :target-path "target/%s"
   :profiles {:uberjar {:aot :all}})
index 7326e425a72c8d73c9759ee06ef7c8ef480e0d8e..d10e74b514cf7d427c7571a086cfc8f5d56b7ee0 100644 (file)
@@ -1,10 +1,10 @@
 (ns adventofcode2019.day12
-    [:require [adventofcode2019.lib :refer :all]
-              [adventofcode2019.intcode :as i]
-              [clojure.string :as str]
-              [clojure.core.match :refer [match]]
-              [clojure.math.combinatorics :as combo]
-              [clojure.pprint :refer [pprint]]])
+  [:require [adventofcode2019.lib :refer :all]
+   [adventofcode2019.intcode :as i]
+   [clojure.string :as str]
+   [clojure.core.match :refer [match]]
+   [clojure.math.combinatorics :as combo]
+   [clojure.pprint :refer [pprint]]])
 
 ; <x=1, y=2, z=3> -> [[1 2 3] [0 0 0]]
 (defn parse-coords [coords]
                               (assoc-in [j 1] nv2))))]
     (mapv velocity (reduce apply-gravity bodies all-pairs))))
 
+(defn find-cycle [states]
+  (let [detect-dup (fn [[ct prev] state]
+                     (if (= (flatten prev)
+                            (map - (flatten state)))
+                       (reduced (inc ct))
+                       [(inc ct) state]))]
+    (* 2 (reduce detect-dup [0 []] states))))
+
 (defn day12 []
   (let [input (mapv parse-coords (get-list-from-file (input-file)))
-        simulate (iterate step-simulation input)] 
+        simulate (iterate step-simulation input)]
     (part1 (reduce + (map total-energy (nth simulate 1000))))
-    #_(part2)))
+    (part2 (find-cycle simulate))))