aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2021-12-23 14:04:23 -0500
committerClyne Sullivan <clyne@bitgloo.com>2021-12-23 14:04:23 -0500
commit0ed8af18c6e551789fc835cf4a77bd995ffbfca3 (patch)
treee2fb4f59ba2c601549327f03d1e89fc33e65d419
parent6dda086d5ccfd194d8fbb51b8d10461605e43c79 (diff)
day23: no more lein app
-rw-r--r--day23/part2.clj (renamed from day23/core.clj)39
1 files changed, 9 insertions, 30 deletions
diff --git a/day23/core.clj b/day23/part2.clj
index 213ce5e..adbefc1 100644
--- a/day23/core.clj
+++ b/day23/part2.clj
@@ -1,12 +1,3 @@
-;
-; Place in new leiningen 'app' template project
-;
-; Run with `java -Xmx8G -jar ...`
-;
-
-(ns hah.core
- (:gen-class))
-
(require '[clojure.core.reducers :as r])
(def init-field
@@ -84,28 +75,16 @@
%1)
(into [] (for [f fields i (range 0 11)] [f i])))))
-(def wins (atom #{}))
-
(defn play-games [turns tc]
(println "Games:" (count turns) "Turn:" tc)
- (if (< 250000 (count turns))
- (do
- (println "Splitting...")
- (doseq [p (partition 50000 turns)]
- (play-games (into #{} p) tc)))
- (do
- (let [new-turns (do-turns turns)
- winners (filter winner? new-turns)]
- (if (pos? (count winners))
- (do
- (println "Winner! Turns:" tc)
- (swap! wins #(reduce conj % (map second winners))))
- (when (pos? (count new-turns))
- (recur new-turns (inc tc))))))))
+ (let [new-turns (do-turns turns)
+ winners (filter winner? new-turns)]
+ (if (seq winners)
+ (map second winners)
+ (recur new-turns (inc tc)))))
-(defn -main
- "I don't do a whole lot ... yet."
- [& args]
- (play-games #{[init-field 0]} 0)
- (println (first (sort @wins))))
+(->> (play-games #{[init-field 0]} 0)
+ sort
+ first
+ ((partial println "Lowest energy:")))