Skip to content

Instantly share code, notes, and snippets.

@dozed

dozed/day5.hs Secret

Created December 9, 2022 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dozed/7f0ea0ec4ac6191b4b978012fcf21923 to your computer and use it in GitHub Desktop.
Save dozed/7f0ea0ec4ac6191b4b978012fcf21923 to your computer and use it in GitHub Desktop.
{-# LANGUAGE QuasiQuotes #-}
module Day5 where
import Control.Monad (void)
import Data.List (transpose)
import Data.Maybe (catMaybes)
import Text.Parsec
import Text.Parsec.String
import Text.RawString.QQ
import Util (regularParse, replaceAtIndex)
testInput1 :: String
testInput1 = [r|
[D]
[N] [C]
[Z] [M] [P]
1 2 3
move 1 from 2 to 1
move 3 from 1 to 3
move 2 from 2 to 1
move 1 from 1 to 2
|]
type Item = Maybe Char
emptyItemParser :: Parser Item
emptyItemParser = Nothing <$ string " "
filledItemParser :: Parser Item
filledItemParser = do
void $ char '['
c <- anyChar
void $ char ']'
return $ Just c
itemParser :: Parser Item
itemParser = emptyItemParser <|> filledItemParser
itemsParser :: Parser [Item]
itemsParser = sepBy1 itemParser $ char ' '
inputParser :: Parser [[Item]]
inputParser = do
void endOfLine
items <- sepBy1 itemsParser endOfLine
endOfLine
many1 anyChar
endOfLine
endOfLine
return items
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment