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.
26 lines
741 B
Clojure
26 lines
741 B
Clojure
3 years ago
|
(require '[clojure.string :as str])
|
||
3 years ago
|
|
||
3 years ago
|
(->> "./in"
|
||
|
(slurp)
|
||
|
(str/split-lines)
|
||
|
(map (fn [l] (map #(if (= % \1) 1 0) l)))
|
||
|
(apply (partial map +))
|
||
|
(map #(if (< % 500) \1 \0))
|
||
|
(str/join)
|
||
|
(#(Integer/parseInt % 2))
|
||
|
(#(* % (bit-xor % (dec (int (Math/pow 2 12))))))
|
||
|
(println)
|
||
|
)
|
||
3 years ago
|
|
||
3 years ago
|
; (->> input data file name
|
||
|
; read in entire contents
|
||
|
; split contents into array of lines
|
||
|
; for each line, transform characters '1'/'0' to numbers
|
||
|
; build sum array using the lines
|
||
|
; convert back to array of characters
|
||
|
; join characters into single string
|
||
|
; convert binary string to a number (gamma)
|
||
|
; multiply gamma by its bit-inverse (bit length hard-coded)
|
||
3 years ago
|
; print results
|
||
3 years ago
|
|