day23: no more lein app

master
Clyne 3 years ago
parent 6dda086d5c
commit 0ed8af18c6

@ -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]) (require '[clojure.core.reducers :as r])
(def init-field (def init-field
@ -84,28 +75,16 @@
%1) %1)
(into [] (for [f fields i (range 0 11)] [f i]))))) (into [] (for [f fields i (range 0 11)] [f i])))))
(def wins (atom #{}))
(defn play-games [turns tc] (defn play-games [turns tc]
(println "Games:" (count turns) "Turn:" tc) (println "Games:" (count turns) "Turn:" tc)
(if (< 250000 (count turns)) (let [new-turns (do-turns turns)
(do winners (filter winner? new-turns)]
(println "Splitting...") (if (seq winners)
(doseq [p (partition 50000 turns)] (map second winners)
(play-games (into #{} p) tc))) (recur new-turns (inc 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))))))))
(defn -main (->> (play-games #{[init-field 0]} 0)
"I don't do a whole lot ... yet." sort
[& args] first
(play-games #{[init-field 0]} 0) ((partial println "Lowest energy:")))
(println (first (sort @wins))))
Loading…
Cancel
Save