Skip to content

Instantly share code, notes, and snippets.

@shapr
Created December 3, 2018 19:10
Show Gist options
  • Save shapr/3064f53ec396de828db8abf7788a2a23 to your computer and use it in GitHub Desktop.
Save shapr/3064f53ec396de828db8abf7788a2a23 to your computer and use it in GitHub Desktop.
parser for day3 2018
{-# 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