executable advent07
import: common-extensions, build-directives
main-is: advent07/Main.hs
- build-depends: text, attoparsec, containers, path-tree, rosezipper
+ build-depends: text, attoparsec, containers, rosezipper
executable advent08
import: common-extensions, build-directives
executable advent25
import: common-extensions, build-directives
main-is: advent25/Main.hs
--- build-depends: split
-- Writeup at https://work.njae.me.uk/2022/12/02/advent-of-code-2022-day-2/
import AoC
-import Data.Text ()
+import Data.Text (Text)
import qualified Data.Text.IO as TIO
import Data.Attoparsec.Text hiding (Result)
import Control.Applicative
-- Parse the input file
+match1P :: Parser [Round]
+match2P :: Parser [ShapeResult]
+roundP :: Parser Round
+shapeResultP :: Parser ShapeResult
+p1ShapeP, p2ShapeP, aP, bP, cP, xP, yP, zP :: Parser Shape
+resultP, xrP, yrP, zrP :: Parser Result
+
match1P = roundP `sepBy` endOfLine
roundP = Round <$> p1ShapeP <*> (" " *> p2ShapeP)
yrP = Draw <$ "Y"
zrP = Win <$ "Z"
--- successfulParse :: Text -> (Integer, [Maybe Integer])
+successfulParse1 :: Text -> [Round]
successfulParse1 input =
case parseOnly match1P input of
Left _err -> [] -- TIO.putStr $ T.pack $ parseErrorPretty err
- Right match -> match
+ Right matches -> matches
+successfulParse2 :: Text -> [ShapeResult]
successfulParse2 input =
case parseOnly match2P input of
Left _err -> [] -- TIO.putStr $ T.pack $ parseErrorPretty err
- Right match -> match
+ Right matches -> matches
import Data.Tree
import Data.Tree.Zipper hiding (tree)
import qualified Data.Map.Strict as M
--- import Data.Map.Strict ((!), (!?))
import Data.List (foldl', sort)
data ParsedObject = CD String
import Data.Text (Text)
import qualified Data.Text.IO as TIO
import Data.Attoparsec.Text hiding (take, D)
-import Control.Applicative
import Data.List
import Data.Ix
import Data.Maybe
import Data.Text (Text)
import qualified Data.Text.IO as TIO
import Data.Attoparsec.Text hiding (take, D)
-import Control.Applicative
-import Data.List
import Data.Ix
import qualified Data.Set as S
import Linear hiding (Trace, trace, distance)
-import Control.Lens
type Position = V2 Int
r1 <> r2 = Region (\p -> getRegion r1 p || getRegion r2 p)
instance Monoid Region where
- mempty = Region (\p -> False)
+ -- mempty = Region (\p -> False)
+ mempty = Region (const False)
main :: IO ()
main =
numStrs <- readFile dataFileName
let fuels = fmap readSnafu $ lines numStrs
putStrLn $ showSnafu $ sum fuels
- -- print $ part1 fuels
readSnafu :: String -> Int
readSnafu cs = foldl' go 0 cs
packSnafu digits
| carry == 0 = shown
| otherwise = (snafuRep carry) : shown
- where (carry, shown) = foldl' packSnafuDigit (0, "") digits
+ where (carry, shown) = foldl' packSnafuDigit (0, "")
packSnafuDigit :: (Int, String) -> Int -> (Int, String)
packSnafuDigit (carry, acc) d