5
[aoc20.git] / 5 / one.icl
1 module one
2
3 import StdEnv
4
5 read :: *File -> [[Int]]
6 read f
7 # (l, f) = freadline f
8 | l.[size l - 1] <> '\n' = []
9 = [[tobin c\\c<-:l % (0, size l - 2)]:read f]
10 where
11 tobin 'B' = 1
12 tobin 'F' = 0
13 tobin 'R' = 1
14 tobin 'L' = 0
15
16 Start w
17 # (io, w) = stdio w
18 # ls = read io
19 = (one ls, findHole (sort (map seatNo ls)))
20
21 findHole x = hd [b+1\\a<-x & b<-tl x & c<-tl (tl x) | a+1 == b && b+1 <> c]
22 one = foldl (\m v->if (v>m) v m) 0 o map seatNo
23 seatNo = foldl (\n s->s + 2*n) 0