module Aoc where
import Text.Parsec
import Text.Parsec.Char
import Text.Parsec.Combinator
import Text.Parsec.String (Parser)
readAndParseStdin :: Parser a -> IO a
readAndParseStdin parser = do
content <- getContents
case parse parser "" content of
Left parseError -> error $ show parseError
Right doc -> return doc
parseMultipleGrids :: Parser [[[Bool]]]
parseMultipleGrids = parseGrid `sepBy` string "\n\n"
parseGrid :: Parser [[Bool]]
parseGrid = parseGridRow `sepBy` char '\n'
parseGridRow :: Parser [Bool]
parseGridRow = many1 parseGridTile
parseGridTile :: Parser Bool
parseGridTile =
choice
[ True <$ char '#',
False <$ char '.'
]