aboutsummaryrefslogtreecommitdiffstats
path: root/day3/part1.clj
blob: c896928a9d843c3e90731e089ceec8955d11222d (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
26
27
28
29
30
31
(def counts
  (loop [line (read-line)
         tot (repeat (count line) 0)
         ]
    (if (empty? line)
      tot
      (recur
        (read-line)
        (map + tot (map #(if (= % \1) 1 0) line))
        )
      )
    )
  )

(loop [cnts counts gamma 0 epsilon 0]
  (if (empty? cnts)
    (println (* gamma epsilon))
    (recur
      (rest cnts)
      (if (> (first cnts) 500)
        (inc (* 2 gamma))
        (* 2 gamma)
        )
      (if (< (first cnts) 500)
        (inc (* 2 epsilon))
        (* 2 epsilon)
        )
      )
    )
  )