From: Neil Smith Date: Thu, 24 Jan 2019 10:33:45 +0000 (+0000) Subject: Partial progress on day 20 X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=4b69139ad3c866105f1bd717bebfa7ea9fed1c29;p=advent-of-code-18.git Partial progress on day 20 --- diff --git a/advent-of-code.cabal b/advent-of-code.cabal index 3e787cf..7a9d811 100644 --- a/advent-of-code.cabal +++ b/advent-of-code.cabal @@ -226,4 +226,15 @@ executable advent19 , containers , mtl , text - , megaparsec \ No newline at end of file + , megaparsec + +executable advent20 + hs-source-dirs: src/advent20 + main-is: advent20.hs + default-language: Haskell2010 + build-depends: base >= 4.7 && < 5 + , containers + , mtl + , text + , megaparsec + , linear diff --git a/data/advent20.txt b/data/advent20.txt new file mode 100644 index 0000000..2945cf8 --- /dev/null +++ b/data/advent20.txt @@ -0,0 +1 @@ +^EESWSWWSSSENNEESWSEEENNW(S|N(ENNNW(NENNESSENENNESESENESENNNESENNNNNWSSWNWSWNNNNNWSSSWSWWNENENNNEEENNWWNENWNWNWSSWSSSWSSSS(ENNNE(NNE(SEEWWN|)N(W|N)|SS)|WSSWWNENWWNNENNWWNNNEEENENES(ENNNWNEENEENEEESSENNENNWSWWWWNWNWSWSWSWWNWWWWNNNENEENEEENWNENEEENWNEEENWNENESSENNNWNNNWWWNNENEESWS(EENNNWWWWNNESEEENESSSEESENNWNNESEESESSWNW(SSSSESWWSWSWNW(SSSEEEN(WW|EN(W|NESSSSSSWWSEEENENESEEENNWSWNWWW(S|NENNNNENWW(NEN(WWSNEE|)NEESEEESWWW(WNSE|)SEESENESSSEEEESSWWSEEESWSEENNNWNENNENWNNEES(EEEENNWWNNWNNWSSWNNWWSESWWNWWNNWSWWWWWWNNNEEEEES(EEEEEN(WWWW|EESWS(WWSWNSENEE|)EEEESENEENWN(EEEEESWWWSEEEEESSWNWWWSSENESSWWSSENESENNNEEESEENENE(SSWSESSSWNNWNWWWW(NEWS|)SSWSSSESEENNW(N(WSNE|)ENN(WSNE|)ESSSSEN(NN|EESWSWWSWWSWSSENESSSSSEENNEE(SSSW(SESWSESWWNWSSEEESSSSWSESWSWNWNENWNWNEESENNWWWWNNWSWWWSSWWWSSSSSWNWNWNNENNWSWSSSWSWWWNWSWWWSWNNWNENNESSENENENWNNWWNENESEEEESSWSSW(NNN(WSNE|)E|SWS(WSWWEENE|)EEE(SWEN|)N(W|E(NN(WSNE|)NE(ENENNNESSSENENNNNNEENENWNWSSWNNNEENWNNESESE(SS(WNSE|)SSEE(NWES|)SSSWNNWSW(WWSESEE(NWES|)EEEEE(NWWEES|)SWWWWS(EESSNNWW|)WSWNWSW(NN(N|EEE)|SSWN(N|WSW(NWES|)SSS(S|W)))|N)|N(NWNNNNWWSWW(SWWSESWSWNWWW(NENEN(E(SSWENN|)EE|W)|SEESESWWNWSSSEESENESEE(SSWWWN(EE|WSSSE(NEEESS|SSWW(SEWN|)N(NNWNNWSSSS(ENSW|)WNNNNWSSS(WWWSWNWWSWNWWNEEEENWWNENEES(SSEENE(NWW(NNWW(WWSWNWSW(N|WWWSWSSSEESWSESSEENNW(NE(NNW(S|NW(WSEWNE|)NEEEESWW(EENWWWEEESWW|))|ESSEN(EESSW(SWW(NEWS|)WWWWSWSEENESESSSENNESSENE(SSSSSENN(ESSSSSWWSSSEENEEEESWWSESWWSWSSEEN(W|NESESWSWSSESWWWSSSWWSSWSEENEN(W|ENNESENN(EEEENENNNWNENNEESSW(SEEENWNENESEEESSWWSESWWWWSWSSWN(WSWSEEESSWSWSWSWWWSSEEEESWSESWSWWNENNWSWWN(E|WWSSSESWSEESWSWWN(WSSSESENESEESWSEEENNESENENEESWSEESSESWWNWWWW(NEE(EE|N)|WWSSESWWNWWSSE(SENESEESWWWSSWWWNEN(ESNW|)WN(NWSWNNEENNEEN(ESNW|)WWWSWNWNNN(WNNE(NWNNNEENE(SSWWSNEENN|)NWNNWNNESE(NNN(WSWNWWSWNWSSSSWNNWNWWNWWWWNENNNENNENNWNEEESSEEENNENWNNEES(SEESSSE(SSW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NNNNNNWNWWNNENEENNNESSSENNNEEESSSSSWNW(NNNESS|WSESSENEEEENWNW(S|NNEEENWNWNW(SSEWNN|)WNEENWWNNNEENEEENNNESSSSSWSESENESSENNENNNNWNWNNW(NNENNN(WSSWSSSWWSWWSS(EENWESWW|)WSWWSWNWSWNNEN(WN(WSSSSWNWNNWW(NWN(W|ENESES(E(NNEN(ESSWENNW|)WW(WWNEEEE(WWWWSEWNEEEE|)|S)|SS)|W))|SSSSEN(ESEESWSSENEENN(WSNE|)ESSE(SWS(WNWSWWSWNNWNW(WN(EEESNWWW|)WSWNNEE(WWSSENSWNNEE|)|SSESWSEEESWWSWWW(N(E(NWES|)E|W)|SEESWWSSE(NEWS|)SWS(WNSE|)S))|E)|NN)|NN))|E)|EES(E|W))|EEENENWNNW(WWN(EEEESSEENWNENENEEEEESWSSWNNWWSESSEESWSSWSSSENNESENEEESENENENNNEENEE(NNNWNWWNE(E|NWWSWSESWWSWWW(SWSSSSWSEEENWNEESSENNE(S|NWWNN(WSWSEWNENE|)EENEES(EN(NW|ES)|SW(N|WW)))|NNENNN(WWW(N|WW(WNWNSESE|)SEESE(ENW|SW))|ESE(SWS(SWEN|)E|NN(WW|EES(WSNE|)ENE(S|NNWSWNNWWNW(NEESEE(N(W|EE)|S)|S)))))))|SWSWWSSESWSSWW(NENSWS|)WWWNWSWSW(SWSWWWWNENNWSWSSSSWW(SSSENNEENEN(EESSSEENESENNWWW(S|NENEEENEN(WWSWENEE|)EESWSEEESWWWSEEESSSSSESWSWNNNNNWWWW(SSSESENE(SSSEEEEESEENWNNWNW(SS(E|W)|NNESEES(W|SSEESWSSWSSWWSSESSWNWWNENWNNNN(WWSSSSSE(NNNN|SWSEESE(ESWWSWNWN(E|WNNNWWWSWNNEENWNNWNNEEE(NWWWWWWSESE(SWSWNWN(E|WNNNNNN(NW(NENSWS|)SSWNNWSSWWSSSW(SEESSSWSWSESWSWSESSSWNWSSSSEEENEENENEEEESSENEENWNENN(WSWS(WNWWNWSS(WWSWNNENNW(NEENNNESEN(ESEESSE(NNNESNWSSS|)SWWW(SEEWWN|)NENWWSW(S(WSSNNE|)E|N)|NWNNWSW(NNWNEEN(ESSWENNW|)WW|S(SSWSEWNENN|)E))|SW(SSSS(WSWNSENE|)E|N))|EE)|S)|EEE(NWES|)SWSSW(SSEEENW(W|NE(NWES|)ESESENESESEESS(EENWNNNNNEESWSEENEENWWNWNWWW(S(EE|WSESWS(SEN|WNW))|NENWN(ENNEEEEEESWWWWWSESS(WNSE|)ESENESEENWNWWN(WSNE|)EEESEEESSWW(NEWS|)SWW(SESWSESEESSENNNEENENESSENNNNESSSESWSWWSWWSW(NNEENSWWSS|)S(WWWWWWWWWNNESENEN(W(NE|WWWS)|ESES(ENSW|)WW)|EENESEENEN(WWSNEE|)NENESENNWWNEEESSESSEEENWNNNNEEEENENWWWWNENEENNESESESW(SSENENENNESSSENENWNNWWN(NEN(EENESSSEEESEEESESSSSSENEESWSSSEESWWSWNWWWWWSEEEESES(ENENESS(EEENNWSWNNEEESSE(SWEN|)NNNWWNNWSSWNWN(WSNE|)ENENNWNWS(S(S|E)|WWNENWW(NENEENNNENEENWNNNNESESWSESSSSSSE(SWSSW(NW(S|WN(W(W|S)|NENE(SSWENN|)NW(NE|WS)))|SESE(NNN|SSSWNNWN(SESSENSWNNWN|)))|NNNNNNNNNWNENNWWWNENEE(SWEN|)NWNENNNWSWWWNWSWWSSESSSWWNENWWSWWWW(SESSESSSEENWNNNWNEESSEEN(W|ESSSSWNNW(W|SSSSEEEE(SWSWNWSSWSS(W(SEWN|)WNENNENWNNWWWNWSSSESWSEE(SSWNWWWNNNE(NWNENWWN(E|WSSESSWNW(NNNWESSS|)W)|SS)|ENWNN(ESNW|)W)|EEN(W|N))|NNNNN(ESENEWSWNW|)W(NNE(S|NWNNN(W|EEE(E|SSW(NWSNES|)S)))|SSSSWW))))|NNWSWNWNEEEEENWNNNWSWWNENENWNNWNN(ESENEESENESENNWWNENENWNWNN(WWWSWSSEESSE(NENW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ENW(NNEES(W|E(SS(WNSE|)SS|ENENNNESE(NN(ESNW|)W(NENWNSESWS|)WWSSWS(S|WWW|E)|SS(WNSE|)SSSENE)))|W)|S))|N))|NWW(SEWN|)N)|SSS))|SSSSSSENN(ESSNNW|)N))))|N)|S)))|N)|N))|NEN(ESNW|)WN(E|N))|NNNNNNNNNNNNNENNNW(SS|NENWNENWNENNESSSSSSSSESSW(N|SEESWSESWWNW(SSEEEENNNNNEEEEENNWWNWNEEENEEEE(NNNNWSWNNNWSSSSS(EENWESWW|)WNWSWWWNWSSE(EEE|SSSWW(S(S|EEE(EE|N))|NN(ESNW|)NNNW(SSSS|NNNESSEEEE(SWEN|)EENWNNNE(SS|NNESSENNEEESS(WSSWNNNE(WSSSENSWNNNE|)|ENNNWWNNNNE(SSS|NNWWWWNENEES(W|ENNWWWNWNNNWSWWSSWNWWNNNNENWWNEENNWNWWSES(E|WSWSWSSW(NNNNE(ENWNNW(SS|NENNW(NNEES(ENENESSWSWSW(SS(S|ENESEESENNESESWSWSSSSSWSE(SWEN|)EENNNW(NEN(W|ESSEEEESSSWW(NN(WSWN|ES)|SSESEEESSENESE(ENE(S|EEEEEEE(SWWWEEEN|)NEENWWWWNWWSWNWWNWSWNNWNWSWNNNW(NNWWSWNW(SSEEEN|W(W|NEEEEENENWWNNWSWNWWNENWWNWNNWWS(ESWSSENESESS(WNWWS(E|W(SEWN|)(N|W))|ES(W|SEN(ESE(E|N)|N)))|WWNNWNEEES(WSNE|)ENESEENESSWWSESENESEENNW(WNNEES(ENENWNEENWNNEES(ENEEESWSSENEEENEESSW(N|SEESESSSEENNNESENNEEEEESWSESWWSSSSWNWSWWNN(NNEESWS(EENNNWNEES(NWWSESNWNEES|)|S)|WSSWNWN(E|WWSSSWWSSWWWSSSWWWWSESWS(ESEENNW(NEESESWSS(ES(W|ENENW(W|NENNENNEENWNW(SWSSWNW(NE|SSES)|NEENE(NWNSES|)EESSSSESWWW(WWSSSW(SSEEEENNENEEN(EEEENESSSWNWS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W)|WW))))))|S)))))|W)|W)|S))))|SSSSSS(WNWESE|)EESEE(EN(WWNNWSWN(SENESSNNWSWN|)|ESE(N|EEE(EE|N)))|S)))|SWSWW(SSEN|NE))))|SS))|N)|W)|S))|S)|SSSSESWSEEENNW(NEE(NWNNW(NE(ESSNNW|)N|SWS(E|S))|SSENESESWWSSESESWWNWNWSWNN(EENSWW|)WWSSE(N|SESESSWSSSSEENEESSSS(ENNNE(SSS|NENWNNWWWNW(N(NWES|)EEES(EENNW(NNN(W(S|W)|NEE(ENWNNWSSW(ENNESSNNWSSW|)|SWSSE(SESSSEE(NWNNN(E(SS|E)|W)|SWWWWNENN(SSWSEEWWNENN|))|N)))|S)|W)|SSWS(EEEN(ESSNNW|)W|S)))|WNN(N|WWWWW(SS|NENNW(S|NNE(S|N(E|NW(N|S)))))))))|S))))))))))|SWSWW(NEWS|)(SEEENENESE(N|S(SWNWSSWWSEESWSWS(WWWNEEN(E|WN(WWWWWSESESWS(W(SSSWWSWWW(NENWNEES(EENWESWW|)S|S(E|SS))|NN)|EE(NNN(W|E)|E))|NNE(SS|EE)))|EEEE(NW(NENNWS|W)|S)|S)|E))|WW))|N(E|N)))))))))|W)|NN)))|NEN(WNEWSE|)ESEE(ES(ENESNWSW|)WW|N(W|N)))|NEEESW)|WSWWSEESWS(E|WNWSWW(NENNNNENEE(S(SW(WSSNNE|)N|E)|NNNE(ES(ENSW|)W|NWWW(NEEEN(N|WW)|SWSW(NNEWSS|)SWWN(W(W|SSS(ENESE(NENEEN(W|N)|S)|W(SEWN|)WWWSWSSWWNWN(W(SSESWENWNN|)W|NESE(NN(ESNW|)W(W|N)|S))))|E))))|SS(WNSE|)E(SWEN|)N))))|WN(NEWS|)WSW(S|N))|S)|W))|E))|EES(ENNWESSW|)W)|S)))|E(S|NN(WSNE|)N)))|ENWNE(E|N))|N))|NNENNNW(NENWWWWW(SEWN|)NEN(ENENNNENENESSSSESWSS(EEN(W|ESSEEE(SSSS(EES(ENENSWSW|)(WW|S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ESWW|))))|SS)|W))$ diff --git a/src/advent20/advent20.hs b/src/advent20/advent20.hs new file mode 100644 index 0000000..96ff894 --- /dev/null +++ b/src/advent20/advent20.hs @@ -0,0 +1,127 @@ +{-# LANGUAGE NegativeLiterals #-} +{-# LANGUAGE OverloadedStrings #-} + + +-- import Debug.Trace + +-- import Prelude hiding ((++)) +import Data.Text (Text) +import qualified Data.Text as T +import qualified Data.Text.IO as TIO + +import Data.Void (Void) +import Text.Megaparsec hiding (State) +import Text.Megaparsec.Char +import qualified Text.Megaparsec.Char.Lexer as L +import qualified Control.Applicative as CA + +import qualified Data.Map.Strict as M +import Data.Map.Strict ((!)) +import qualified Data.Set as S + +import Linear (V2(..)) + +import Control.Monad.State.Lazy + +type Coord = V2 Integer -- x, y, with north and east incresing values (origin a bottom left) +data Door = Door Coord Coord deriving (Show, Eq, Ord) +type Doors = S.Set Door + +makeDoor :: Coord -> Coord -> Door +makeDoor a b + | a < b = Door a b + | otherwise = Door b a + + + + +main :: IO () +main = do + text <- TIO.readFile "data/advent20.txt" + print $ T.length text + -- let (ip, instrs) = successfulParse text + -- print (ip, instrs) + -- -- print $ part1 ip instrs + -- print $ sum [i | i <- [1..1032], 1032 `mod` i == 0] + -- -- print $ part2 ip instrs + -- print $ sum [i | i <- [1..10551432], 10551432 `mod` i == 0] + + + +-- type Parser = Parsec Void Text +type Parser = ParsecT Void Text (StateT [Coord] []) + + +sc :: Parser () +sc = L.space (skipSome spaceChar) CA.empty CA.empty + +lexeme = L.lexeme sc +-- integer = lexeme L.decimal +symb = L.symbol sc +branchSepP = symb "|" +openBranchP = symb "(" +closeBranchP = symb ")" +startP = symb "^" +endP = symb "$" + +doorP :: Parser Coord +doorP = nP <|> sP <|> eP <|> wP +nP = (symb "N" *> pure (V2 0 1)) +sP = (symb "S" *> pure (V2 0 -1)) +eP = (symb "E" *> pure (V2 1 0)) +wP = (symb "W" *> pure (V2 -1 0)) + +-- instructionFileP = (startP `between` endP) branchesP + +-- branchesP :: MyParser Doors +-- branchesP = fmap S.unions . many $ choiceP <|> pathP + +-- choiceP :: MyParser Doors +-- choiceP = (openBranchP `between` closeBranchP) $ do +-- here <- get +-- return fmap S.unions (`sepBy` branchSepP) $ do +-- put here +-- return branchesP + + + +-- pathP :: MyParser Doors +-- pathP = S.fromList <$> many stepP +pathP = many stepP + +-- stepP :: MyParser Door +stepP = do + heres <- get + delta <- doorP + let theres = map (+delta) heres + put theres + return (map (\h -> makeDoor h (h + delta)) heres) + +-- choiceP :: MyParser [Door] +-- choiceP = (openBranchP `between` closeBranchP) $ do +-- heres <- get +-- do +-- here <- heres +-- put [here] +-- branch <- (pathP `sepBy` branchSepP) +-- return branch + + -- fmap concat $ (`sepBy` branchSepP) $ do + -- here <- heres + -- pathP + + +{- heres <- get + choices <- (`sepBy` branchSepP) $ do + put heres + pathP + return $ concat choices -- (S.unions choices)-} + +-- choiceOrPathP = many (choiceP <|> pathP) + + +-- successfulParse :: Text -> (Integer, [Instruction]) +-- successfulParse input = +-- case parse instructionsP "input" input of +-- Left _error -> (0, []) -- TIO.putStr $ T.pack $ parseErrorPretty err +-- Right instructions -> instructions \ No newline at end of file