In progress
This commit is contained in:
parent
538fba7063
commit
47bafe66dc
2 changed files with 41 additions and 0 deletions
2
day13/input
Normal file
2
day13/input
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
1000507
|
||||||
|
29,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,37,x,x,x,x,x,631,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,13,19,x,x,x,23,x,x,x,x,x,x,x,383,x,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,17
|
39
day13/main.hs
Executable file
39
day13/main.hs
Executable file
|
@ -0,0 +1,39 @@
|
||||||
|
#! /usr/bin/env -S"ANSWER=42" nix-shell
|
||||||
|
#! nix-shell -p ghcid
|
||||||
|
#! nix-shell -p "haskellPackages.ghcWithPackages (p: with p; [pretty-simple attoparsec])"
|
||||||
|
#! nix-shell -i "ghcid -c 'ghci' -T main"
|
||||||
|
|
||||||
|
{-# OPTIONS_GHC -Wall -Wincomplete-uni-patterns #-}
|
||||||
|
{-# OPTIONS_GHC -Wno-unused-top-binds -Wno-unused-imports #-}
|
||||||
|
{-# OPTIONS_GHC -Wno-unused-matches #-}
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
|
import Control.Applicative
|
||||||
|
import Data.Attoparsec.Text (Parser)
|
||||||
|
import Data.Text (Text)
|
||||||
|
import Debug.Trace (trace)
|
||||||
|
import Text.Pretty.Simple
|
||||||
|
import qualified Data.Attoparsec.Text as A
|
||||||
|
import qualified Data.Text as T
|
||||||
|
|
||||||
|
exampleData :: String
|
||||||
|
exampleData = "939\n7,13,x,x,59,x,31,19"
|
||||||
|
|
||||||
|
numOrXParser :: Parser Text
|
||||||
|
numOrXParser = A.takeWhile (/= ',')
|
||||||
|
|
||||||
|
inputParser :: Parser (Int,[Int])
|
||||||
|
inputParser = do
|
||||||
|
n <- A.decimal
|
||||||
|
A.skipSpace
|
||||||
|
xs <- numOrXParser `A.sepBy` ","
|
||||||
|
pure (n,read <$> T.filter (/= ',') xs)
|
||||||
|
|
||||||
|
parseInput :: String -> Either String (Int,[Int])
|
||||||
|
parseInput = (A.parseOnly inputParser) . T.pack
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = do
|
||||||
|
putStrLn ":: Test"
|
||||||
|
A.parseTest inputParser $ T.pack exampleData
|
||||||
|
putStrLn ":: Day 13 - Part 1"
|
Loading…
Reference in a new issue