8 read :: *File -> [String]
10 # (l, f) = freadline f
11 | l.[size l - 1] <> '\n' = []
12 = [l % (0, size l - 2):read f]
20 one = numOccupied o cell isOccupied ((==)0) ((<=)4)
21 two = numOccupied o cell seeOccupied ((==)0) ((<=)5)
23 isOccupied :: Int Int Int Int {#String} -> Bool
24 isOccupied x y dx dy ls = seat (x+dx) (y+dy) ls == '#'
26 seeOccupied :: Int Int Int Int {#String} -> Bool
27 seeOccupied x y dx dy ls = case seat (x+dx) (y+dy) ls of
31 '.' = seeOccupied (x+dx) (y+dy) dx dy ls
33 numOccupied :: {#String} -> Int
34 numOccupied ls = length [()\\r<-:ls, c<-:r | c == '#']
36 cell :: (Int Int Int Int {#String} -> Bool) (Int -> Bool) (Int -> Bool) {#String} -> {#String}
37 cell lookfun live die ls
38 # ls` = {{step x y\\x<-[0..size ls.[y] - 1]}\\y<-[0..size ls - 1]}
39 = if (and [l==r\\l<-:ls` & r<-:ls]) ls (cell lookfun live die ls`)
41 step x y = case ls.[y,x] of
43 'L' = if (live numOccupied) '#' 'L'
44 '#' = if (die numOccupied) 'L' '#'
46 numOccupied = length [()\\dx<-[-1..1], dy<-[-1..1] | not (dx == 0 && dy == 0) && lookfun x y dx dy ls]
48 seat :: Int Int {#String} -> Char
50 | y < 0 || y >= size ls || x < 0 || x >= size ls.[y] = '-'