You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
704 B
Clojure
37 lines
704 B
Clojure
3 years ago
|
(require '[clojure.string :as str])
|
||
|
|
||
3 years ago
|
(def bitcount 12)
|
||
|
(def input
|
||
3 years ago
|
(->> "./in"
|
||
|
(slurp)
|
||
|
(str/split-lines)
|
||
|
(map #(Integer/parseInt % 2))
|
||
3 years ago
|
)
|
||
|
)
|
||
|
|
||
|
(defn countbit [lst bit]
|
||
|
(->> lst
|
||
|
(map #(if (bit-test % bit) 1 0))
|
||
|
(apply +)
|
||
|
)
|
||
|
)
|
||
3 years ago
|
|
||
3 years ago
|
(defn filterbit [lst bit v]
|
||
|
(if (= 1 (count lst))
|
||
|
lst
|
||
3 years ago
|
(filter #(= (bit-test % bit) v) lst)
|
||
3 years ago
|
)
|
||
|
)
|
||
|
|
||
|
(loop [bit (dec bitcount) lst0 input lst1 input]
|
||
|
(if (and (= 1 (count lst0)) (= 1 (count lst1)))
|
||
3 years ago
|
(println (map * lst0 lst1))
|
||
3 years ago
|
(recur
|
||
|
(dec bit)
|
||
|
(filterbit lst0 bit (>= (countbit lst0 bit) (/ (count lst0) 2)))
|
||
|
(filterbit lst1 bit (< (countbit lst1 bit) (/ (count lst1) 2)))
|
||
|
)
|
||
|
)
|
||
|
)
|
||
|
|