Skip to content

Instantly share code, notes, and snippets.

Created December 2, 2018 17:12
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
#?(:cljs [planck.core :refer [line-seq read-string]])
[#?(:clj :cljs :as io]
[ :as day-01])
(:import (java.util.concurrent Executors ExecutorService)))
(def input (->> "advent_2018/day_02/input" io/resource io/reader line-seq))
(defn count-with-exact [box-ids n]
(->> box-ids
(map frequencies)
(map vals)
(keep #(some #{n} %))
(defn part-1 []
(* (count-with-exact input 2) (count-with-exact input 3)))
(defn delete [idx s]
(str (subs s 0 idx) (subs s (inc idx))))
;; Single thread
(defn part-2 []
(some (fn [idx]
(->> input
(map (partial delete idx))
;; Parallel version
(def pool (Executors/newCachedThreadPool))
(defn part-2' []
(let [p (promise)]
(doseq [idx (range 26)]
(.submit pool
#(when-some [result (->> input
(map (partial delete idx))
(deliver p result))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment