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

(require '[clojure.string :as str])
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
; (->> 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)
; print results