8 read :: *File -> [String]
10 # (l, f) = freadline f
11 | l.[size l - 1] <> '\n' = []
12 = [l % (0, size l - 2):read f]
20 instance == {#String} where
21 (==) l r = and [l==r\\l<-:l & r<-:r]
23 one :: {#String} -> Int
24 one ls = length [()\\r<-:cell ls, c<-:r | c == '#']
26 cell :: !{#String} -> {#String}
27 cell ls = let ls` = step ls in if (ls` == ls) ls (cell ls`)
29 step :: !{#String} -> {#String}
30 step ls = {{step` x y\\x<-[0..size ls.[0] - 1]}\\y<-[0..size ls - 1]}
32 step` :: Int Int -> Char
33 step` x y = case ls.[y,x] of
35 'L' = if (occupied == 0) '#' 'L'
36 '#' = if (occupied >= 4) 'L' '#'
38 occupied = length [()\\dx<-[-1..1], dy<-[-1..1] | not (dx == 0 && dy == 0) && not (empty (x+dx) (y+dy))]
39 empty :: Int Int -> Bool
41 | x < 0 || x >= size ls.[0] || y < 0 || y >= size ls = True