aboutsummaryrefslogtreecommitdiffstats
path: root/day3/part1.clj
blob: 915ee47e50fdb8bf6195ab6b47d1ab74e8126188 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
(require '[clojure.string :as str])

(println
  (->> "./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))))))
       )
  )

; (->> 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)