data Seat = Occupied | Empty
toList $ concat $ toList $ fmap (fmap disp) board
where disp Nothing = '.'
disp (Just Occupied) = '#'
disp (Just Empty) = 'L'
Nothing
status 'L' = Just Empty
status _ = undefined
fromList . fmap fromList . ((status <$>) <$>) . lines
half ++ ((negate *** negate) <$> half)
where half = [(1,0),(0,1),(1,1),(1,-1)]
(++) = (L.++)
fromMaybe False
$ foldl' f Nothing
$ map (fmap isOccupied . uncurry index)
$ takeWhile (\(x,y) -> 0 <= x && x < width && 0 <= y && y < height)
$ fromList $ (((x+) . (xOffs*)) &&& ((y+) . (yOffs*))) <$> [1..]
where
-- index x y = (board ! y) ! x
index = flip (.) (board !) . flip (!)
height = length board
width = length (head board)
isOccupied Occupied = True
isOccupied Empty = False
f (Just x) (Just y) = Just x
f (Just x) Nothing = Just x
f Nothing (Just y) = Just y
f Nothing Nothing = Nothing
fmap (uncurry stepSeat <$>) $
generate height (\y -> generate width (\x -> (x,y)))
where
index = flip (.) (board !) . flip (!)
height = length board
width = length (head board)
seatChange visible Occupied = if visible > 4 then Empty else Occupied
seatChange visible Empty = if visible == 0 then Occupied else Empty
let visible = L.length $ L.filter (seatVisible board (x,y)) directions
in seatChange visible <$> index x y
if x' == x then x' else fix f x'
where x' = f x
(parse <$>) . readFile
do
board <- readBoard s
let equilibrium = fix step board
print $ length $ filter isOccupied $ concat $ toList $ equilibrium
return ()
where
isOccupied (Just Occupied) = True
isOccupied _ = False
solve "input.txt"