-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday03p2.arc
More file actions
30 lines (24 loc) · 751 Bytes
/
day03p2.arc
File metadata and controls
30 lines (24 loc) · 751 Bytes
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
(load "day03p1.arc")
(def extract-column (seq i)
(map [_ i] seq))
(def criticize (col)
(commonest (cons 1 col))) ; add a 1, since commonest returns 0 on equal counts
(def gamma (cols)
(map car:criticize cols))
(def find-rating (seq critf)
(ccc
(fn (ep)
(forlen i (car seq)
(= cols (accum acc
(forlen i (car seq)
(acc (extract-column seq i)))))
(= crit (critf cols))
(pull [isnt (_ i) (crit i)] seq)
(when (is 1 (len seq))
(ep (car seq)))))))
(def run-puzzle (e)
(withs (inp (map [coerce _ 'cons] (puzzle-input 03 'strs e))
intlist (map [map int:string _] inp))
(*
(bin2dec (find-rating (copylist intlist) gamma))
(bin2dec (find-rating (copylist intlist) epsilon)))))