Created
December 3, 2018 19:10
-
-
Save shapr/3064f53ec396de828db8abf7788a2a23 to your computer and use it in GitHub Desktop.
parser for day3 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
module Main where | |
import Data.Text (Text) | |
import qualified Data.Text as T | |
import qualified Data.Text.IO as TIO | |
import Data.Attoparsec.Text | |
main :: IO () | |
main = do input <- TIO.readFile "input3.txt" | |
let ls = T.lines input | |
print "day 3 part 1" | |
let claims = fromRight $ parseOnly (pClaim `sepBy` char '\n') input | |
print claims | |
data Claim = Claim { n :: Integer | |
, col :: Integer | |
, row :: Integer | |
, width :: Integer | |
, height :: Integer | |
} deriving (Show) | |
test :: Text | |
test = "#11 @ 569,720: 28x29" | |
pClaim = Claim <$ char '#' | |
<*> decimal | |
<* string " @ " | |
<*> decimal | |
<* char ',' | |
<*> decimal | |
<* string ": " | |
<*> decimal | |
<* char 'x' | |
<*> decimal | |
fromRight (Right x) = x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment