aboutsummaryrefslogtreecommitdiff
path: root/2023/10-Pipe_Maze
diff options
context:
space:
mode:
authorJulien Dessaux2023-12-10 19:06:11 +0100
committerJulien Dessaux2023-12-10 19:06:11 +0100
commit8cfb87d1d061a7b6248aa6f003f9220050c04937 (patch)
tree39138420bd0bcff02aadc3887e620bbd39e94d8c /2023/10-Pipe_Maze
parent2023-09 in haskell (diff)
downloadadvent-of-code-8cfb87d1d061a7b6248aa6f003f9220050c04937.tar.gz
advent-of-code-8cfb87d1d061a7b6248aa6f003f9220050c04937.tar.bz2
advent-of-code-8cfb87d1d061a7b6248aa6f003f9220050c04937.zip
2023-10 in haskell
Diffstat (limited to '2023/10-Pipe_Maze')
-rw-r--r--2023/10-Pipe_Maze/example5
-rw-r--r--2023/10-Pipe_Maze/example25
-rw-r--r--2023/10-Pipe_Maze/example39
-rw-r--r--2023/10-Pipe_Maze/example410
-rw-r--r--2023/10-Pipe_Maze/example510
-rw-r--r--2023/10-Pipe_Maze/first.hs124
-rw-r--r--2023/10-Pipe_Maze/input140
-rw-r--r--2023/10-Pipe_Maze/second.hs150
8 files changed, 453 insertions, 0 deletions
diff --git a/2023/10-Pipe_Maze/example b/2023/10-Pipe_Maze/example
new file mode 100644
index 0000000..7650925
--- /dev/null
+++ b/2023/10-Pipe_Maze/example
@@ -0,0 +1,5 @@
+.....
+.S-7.
+.|.|.
+.L-J.
+.....
diff --git a/2023/10-Pipe_Maze/example2 b/2023/10-Pipe_Maze/example2
new file mode 100644
index 0000000..682499d
--- /dev/null
+++ b/2023/10-Pipe_Maze/example2
@@ -0,0 +1,5 @@
+..F7.
+.FJ|.
+SJ.L7
+|F--J
+LJ...
diff --git a/2023/10-Pipe_Maze/example3 b/2023/10-Pipe_Maze/example3
new file mode 100644
index 0000000..bd9cdf5
--- /dev/null
+++ b/2023/10-Pipe_Maze/example3
@@ -0,0 +1,9 @@
+...........
+.S-------7.
+.|F-----7|.
+.||.....||.
+.||.....||.
+.|L-7.F-J|.
+.|..|.|..|.
+.L--J.L--J.
+...........
diff --git a/2023/10-Pipe_Maze/example4 b/2023/10-Pipe_Maze/example4
new file mode 100644
index 0000000..adaae96
--- /dev/null
+++ b/2023/10-Pipe_Maze/example4
@@ -0,0 +1,10 @@
+.F----7F7F7F7F-7....
+.|F--7||||||||FJ....
+.||.FJ||||||||L7....
+FJL7L7LJLJ||LJ.L-7..
+L--J.L7...LJS7F-7L7.
+....F-J..F7FJ|L7L7L7
+....L7.F7||L7|.L7L7|
+.....|FJLJ|FJ|F7|.LJ
+....FJL-7.||.||||...
+....L---J.LJ.LJLJ...
diff --git a/2023/10-Pipe_Maze/example5 b/2023/10-Pipe_Maze/example5
new file mode 100644
index 0000000..8f950ae
--- /dev/null
+++ b/2023/10-Pipe_Maze/example5
@@ -0,0 +1,10 @@
+FF7FSF7F7F7F7F7F---7
+L|LJ||||||||||||F--J
+FL-7LJLJ||||||LJL-77
+F--JF--7||LJLJ7F7FJ-
+L---JF-JLJ.||-FJLJJ7
+|F|F-JF---7F7-L7L|7|
+|FFJF7L7F-JF7|JL---7
+7-L-JL7||F7|L7F-7F7|
+L.L7LFJ|||||FJL7||LJ
+L7JLJL-JLJLJL--JLJ.L
diff --git a/2023/10-Pipe_Maze/first.hs b/2023/10-Pipe_Maze/first.hs
new file mode 100644
index 0000000..eedc329
--- /dev/null
+++ b/2023/10-Pipe_Maze/first.hs
@@ -0,0 +1,124 @@
+-- requires cabal install --lib megaparsec parser-combinators
+module Main (main) where
+
+import Control.Applicative.Permutations
+import Control.Monad (void, when)
+import Data.Char qualified as C
+import Data.Either
+import Data.Functor
+import Data.List qualified as L
+import Data.Map qualified as M
+import Data.Maybe
+import Data.Set qualified as S
+import Data.Vector qualified as V
+import Data.Void (Void)
+import Text.Megaparsec
+import Text.Megaparsec.Char
+
+import Debug.Trace
+
+exampleExpectedOutput = 4
+
+data Direction = N | S | E | W deriving (Eq, Show)
+data Tile = NS | NE | NW | EW | ES | WS | Floor | Start deriving (Eq, Show)
+type Line = V.Vector Tile
+type Input = V.Vector Line
+
+type Parser = Parsec Void String
+
+parseTile :: Parser Tile
+parseTile = char '|' $> NS
+ <|> char 'L' $> NE
+ <|> char 'J' $> NW
+ <|> char '-' $> EW
+ <|> char 'F' $> ES
+ <|> char '7' $> WS
+ <|> char '.' $> Floor
+ <|> char 'S' $> Start
+
+parseLine :: Parser Line
+parseLine = do
+ line <- some parseTile <* eol
+ return $ V.generate (length line) (line !!)
+
+parseInput' :: Parser Input
+parseInput' = do
+ line <- some parseLine <* eof
+ return $ V.generate (length line) (line !!)
+
+parseInput :: String -> IO Input
+parseInput filename = do
+ input <- readFile filename
+ case runParser parseInput' filename input of
+ Left bundle -> error $ errorBundlePretty bundle
+ Right input' -> return input'
+
+compatible :: Tile -> Direction -> Bool
+compatible NS N = True
+compatible NS S = True
+compatible NE N = True
+compatible NE E = True
+compatible NW N = True
+compatible NW W = True
+compatible EW E = True
+compatible EW W = True
+compatible ES E = True
+compatible ES S = True
+compatible WS W = True
+compatible WS S = True
+compatible _ _ = False
+
+type Position = (Int, Int)
+type Heading = (Position, Direction)
+
+compute :: Input -> Int
+compute input = walk start 0 `div` 2
+ where
+ walk :: Heading -> Int -> Int
+ walk h i | tile (fst h) == Just Start = i+1
+ | otherwise = walk h' (i+1)
+ where
+ h' = step h
+ step :: Heading -> Heading
+ step (p@(x, y), N) | tile p == Just NS = ((x, y-1), N)
+ | tile p == Just ES = ((x+1, y), E)
+ | tile p == Just WS = ((x-1, y), W)
+ step (p@(x, y), S) | tile p == Just NS = ((x, y+1), S)
+ | tile p == Just NE = ((x+1, y), E)
+ | tile p == Just NW = ((x-1, y), W)
+ step (p@(x, y), E) | tile p == Just NW = ((x, y-1), N)
+ | tile p == Just EW = ((x+1, y), E)
+ | tile p == Just WS = ((x, y+1), S)
+ step (p@(x, y), W) | tile p == Just NE = ((x, y-1), N)
+ | tile p == Just EW = ((x-1, y), W)
+ | tile p == Just ES = ((x, y+1), S)
+ start = head $ catMaybes [startn, starte, starts, startw]
+ startn = nearStart (sx, sy-1) N
+ starts = nearStart (sx, sy+1) S
+ starte = nearStart (sx+1, sy) E
+ startw = nearStart (sx-1, sy) W
+ nearStart :: Position -> Direction -> Maybe Heading
+ nearStart p d = case tile p of
+ Just t -> if compatible t d then Just (p, d) else Nothing
+ Nothing -> Nothing
+ (sx, sy) = (x, y) -- start
+ where
+ hasNoStart :: Line -> Bool
+ hasNoStart = V.all (/= Start)
+ y = length $ V.takeWhile hasNoStart input
+ x = length $ V.takeWhile (/= Start) (input V.! y)
+ tile :: Position -> Maybe Tile
+ tile (x, y) = case input V.!? y of
+ Just line -> line V.!? x
+ Nothing -> Nothing
+
+main :: IO ()
+main = do
+ example <- parseInput "example"
+ let exampleOutput = compute example
+ when (exampleOutput /= exampleExpectedOutput) (error $ "example failed: got " ++ show exampleOutput ++ " instead of " ++ show exampleExpectedOutput)
+ example2 <- parseInput "example2"
+ let exampleOutput2 = compute example2
+ when (exampleOutput2 /= 8) (error $ "example failed: got " ++ show exampleOutput2 ++ " instead of " ++ show 8)
+ input <- parseInput "input"
+ print $ compute input
diff --git a/2023/10-Pipe_Maze/input b/2023/10-Pipe_Maze/input
new file mode 100644
index 0000000..63c06e1
--- /dev/null
+++ b/2023/10-Pipe_Maze/input
@@ -0,0 +1,140 @@
+77.FFFF|-77FFL-F-7--F7.|-7.F|7FFF|-FL7-777F.L-FL7.L7--7.|.7-.J-7-J.F-L77F-7-L7F-F.F7-FL-|--7--JF|7.-7FFL7F-F7-F.FF|-F7LF-FLJFLF-J.F7F--F77..
+|-L7--|.FLJJL|FF7L|FF|-F.LJFLFLJ|L.LL-7L7J|L7.FJL||L7J|-|-777|.LF77|J|.F|L|..J|FL7L--7J.JL|7-|7F||F-FLJ|-F7|J||FF-7LLJ7J-JJ|-LJF.7-F|LF7|L7F
+L7L|J-|F-77|F|J||.L|7JL|-7F-.|J.|-J77-7||J7LJ7|..L-L-7L7--|-F-J-L7J||F-|J.7-F.|77LF-JJ|FF|FLJLJLFJ7-|7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|F||L----7F-J|FJFFJFJ|L-JL7|LJL--7||7|F-J-|.|.||.
+----F---|.LF-FF7L---7||FJF7|||FJ|L7FJL7L-7|L|FJFJL-7|F7F7LJL7||L7FJ|F-J||FJL7F--J|L-7L-7L7|F7||-F---JL-7||F7L7|-|F---JL7F---J|L7|L-7JJ|.7L|J
+L|LLJ.|JL|-|-FJL----JLJ|FJLJLJL7L7|L7FJF-J|FJL7|F--JLJLJL7F-J|L7|L7||LFJLJF7|L--7L7-L7FJ7|LJLJL7L---7F-J|LJ|FJL7|L---7FJL-7F7|FJ|F-J.7LF7-LJ
+.L7.|7|FF-777|F---7F7F7||F-----JFJL7|L7L-7|L-7|||FF--7F7J|L-7L7||FJ|L7L-7FJLJF7FJFJF7|L--JF----JF7F7|L7FJF-JL-7||F---JL7F-J||||FJL---7-.JFJ|
+|JJLJ.FFL7L77||LFFJ|LJ|LJL7F---7L7FJ|FJF-JL--JLJL7L7FJ|L7|F-JL||||.|FJF-JL--7|||FJFJ|L---7|F7F--J||||FJL7|F--7||||F7FF7||-FJ||LJF7F--JL-.7JL
+L7.|L|JF-JFJFLJF7L-JF-JF-7||F--JFJL7|L7L----7F7F-JFJL7|FJ|L7F7|||L7|L7L7F---J|LJL-JFJF---J|||L--7|||||F7|||F-J|LJLJL7|||L7|FJ|F-JLJ7LLJ...L|
+.L7F-7FL-7L7F-7|L---JF7|FJLJL--7|F-JL7|F7LF7||LJF7L-7LJL7L7LJ|||L7|L7|FJL---7L--7F-J7L--7FJ||F7FJLJ|||||||||F7L--7F-J|||FJ|L-JL--7||.F7-77FL
+L-|--F7F7L7LJFJL7F7F7|LJL-7F---J|L7FFJ||L-JLJL77|L77L-7FJFJF7||L7||FJLJF-7F-JF--J|-F7F7FJL7|LJ|L-7FJ|||||||||L-7F|L7FJLJL-JF---7FJJ.F7||JF-J
+|J.|.||||FJF-J7-LJLJLJFF7FJL7FF7|FJFJFJL--7F-7L7L7L7LFJL7L-J||L7||LJF--J.LJF7L7F-JFJ||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7||F----J7-.|.
+FJ7FFJFL-7||LJLJL--J|||7L-JF----J|F-----J|LJL-7LJL--J7FJF-7L7LLJL-7|L7|LJ|FJF7.||FJ||L--7FJF7L-7F7FJ||F-JLJLJF----7L-JFJF7F7J|LJ|L--7LLJFF-7
+|LFJ.7LLFJLJF-------JLJF-7FJF7F7FJL------JF7F-JFF7F7F7L-JFJFJ.LF7FJL7||F-J|FJL-J|L-JL--7|L-JL-7|||L7|LJF--7F-JJF-7L7F7L-JLJL7F-7|F--JJ.LL|.F
+|7||-777L--7|F--------7|FJL7|||LJF------7FJ|L--7|||||L-77L-JF|L|LJF7|LJL7FJ|F7F7|F7F-7FJ|7F7F7|LJL-JL--JF7LJ-F7L7|LLJL7F----J|FJLJF-7.F.|J7J
+7JLLF.FF7F-J|L----7F-7LJL-7LJLJF-JF7F7F7LJLL---J|LJLJF-JF----7-L-7|LJJ-|||FLJ|||||||FJL7L-JLJLJF-7F7F--7||F--JL7||F7F7LJF7F7FJL---JFJ-|-J-F7
+.L7J|F-JLJF7L7F7F-J|FJF7F7|F-7JL--JLJLJL7FF-7F7FJF7F-JF7|F---JF--J|F7J7FLJF--J|LJ|LJ|F7|F-7F---J7LJLJF7LJLJF7F7LJLJLJL--JLJLJF-7F--JJFJ.|7||
+7-|7F|F7F7||FJ||L--JL7|LJ||L7L--7F7F-7F7L7L7||||FJLJF-JLJL--7LL--7LJL77LJJL7F7|.FJF7LJ|||FJ|F--------JL-7F-J|||F7F7F-7F-7F7F7L7||F7JF|.J7|-J
+L7LJ-LJ||LJLJFJL7F--7LJF-J|FL--7LJLJJLJL7L-JLJLJL-7||F-----7|-LLFJF-7L-7L7FLJLJ7L-JL-7|||L-JL--7F---7F-7LJF7LJLJLJLJ|LJFLJLJL-J|||L-7.L7LJ||
+|FF||.LLJ-F77L-7|L-7|F7L-7L---7|F--7F--7|F-------7L-JL---7FJ|7|LL-JJL--J77-F7F7F7LF--J|LJF----7||F7-LJJL--JL--7F7JF77F-----7F77LJ|F-J7.FJF7-
+F-|L-7FJ.FJ|F--JL-7||||F7L---7|LJF7LJF7|LJF-----7|F----7FJL-J7LJ.L|7-LLL-F-JLJLJL7L--7L7-L---7|LJ||F----------J|L-JL7|F----J|L7JFJL--77F7||J
+J-L7LJJJ7L7LJF-7F7LJLJLJL----JL--JL--JLJF7|F--7FJLJF7F7LJJLLF7FF---J.|JLFL--7F--7|LF7L7L7F7F7||F-J|L--7F----7F7|F--7LJL-7F7-L7|FJF---J-JJ7||
+J7-J7J|7FFJF-J-LJL-7F---7F7F-------7F--7|LJL-7|L7F7|LJL7F7JL||7J.|JFJJ..LF--J|F-JL7||FL7LJLJ|||L7FJ-F7||F-7FJ|||L7JL7F-7LJL7FJLJFJF7F7J|---J
+F|JJ|FJ-FJFJLF77F7FJ|JF-J|LJF7F7F--J|F-JL-7F-JL-J|||F-7L7F7FJL77.7F|J|..|L7F-J|F-7LJ|F7|F--7LJL-J|F7|LJ|L7|L-JLJFJF7LJJL---JL7F7L-JLJL-7-7|J
+7||F|7--L7|F-JL-JLJFJFJF-JF7||||L---JL7-F7|L--7F7|||L7L-J|LJF7L77.-JF7J--LLJ|FJ|FJF7LJ|LJF-JF-7F7|||L--J-|L7F7F7L7|L-7F7F7F7FJ|L7F-7F7FJJ|LL
+|FLFJF-JLLJL---7F7FJ-L-JF-J||LJL-----7L7|||F--J|||||FJ7F7L7FJL-J77|.|L|.|FF7-L-JL-JL-7|F7|F7|F|||LJL7F-7FJLLJLJL-J|F-J|||LJLJFJ-LJ7LJLJ|.-..
+FJ.|L|J|7F-----J|LJ|F7F7L-7|L--7F---7L7LJLJL---JLJLJL7FJL-JL---7-7L-J7JFFFJL-----7F7FJLJLJ|||FJ||F-7||FJL7F7F--7F7||F7||L7F-7|F7LF-7FJ--|FL|
+-J-L-|FF-L-7F7F7|F--JLJL--JL---J|F--JLL7F7F-7F7F7F7F-J|F-------J-J.JL|7FLL------7LJLJF7F7FJ||L7|LJFJLJL--J|LJF7LJLJLJLJL-JL7|LJL-JFJ7J-L--7|
+F|-F-|-J|F-J|||LJL-7F7F-7F7F7F7FJL----7|||L7||||LJLJF-JL--7F7F7F7.7J7|F7|-LF7F-7L7F-7|LJ||FJL7LJJFJF-7F7F-JF-JL---------7F7|L7F--7L7.|.FL-7J
+F|.F-F7F-L7FJ||F---J|LJFJ|LJ||LJJF----JLJL-JLJLJJF7FJF----J|LJLJL-7-FF7F7FF||L7L-J|FJ|F7LJL-7|F--JFJ-LJLJF7L-----------7||LJ||L-7L-J-JF7L777
+7L-|7.FJFLLJ.LJL----JF7L7|F-J|JF7L--7F7F--7F7F7F7|LJFJJF77FJF7F---J.FJLJ|F-JL7L---J|FJ|L--7JLJL--7|F-----J|F-----7F7F7FJ|L--7|F7L--7-LLJF-JL
+|.|.FFJJ7FJ--J|.F7F7L||.LJL-7|FJL---J|LJF-J|||||LJF-JF7||FJFJ||F7F-7L7F-JL--7L7F7F-JL7L--7|F7F7F-J|L-----7|L--7F7LJLJ|L7|F7FJ||L7F7L77J-LJ..
+LF..JJ.F-|F7--F-JLJ|FJL-----J|L----7FJF-JF7|||||F7L--JLJLJFJ.LJ|LJFJFJ|F7F-7L7LJLJF7FJF--JLJLJ|L--J.F7FF7|L--7LJL---7L-J||LJJ|L7||L7L7-77|FJ
+7L-7JJ7F||FFJFL---7|L7F-7F---J|F7F7LJFJF-JLJ|||||L-7F7F7F-JF7-FJF-JFL7|||L7|7|F7F-JLJ|L-7F---7|F7F--JL-JLJF-7L7F-7F7L--7|L--7L7||L7L-J|F7F|J
+LF.|.|7.|7||-F-7F-JL7LJJLJF----J||L--JLL7F--J||||F7LJ||||F-JL7|FJF7F7||||FJL7LJ|L7F--7F7LJF--JLJ|L--7F----JFJ|LJ7LJL---JL-7FJFLJL7L7J-JFLJJ|
+F|-|7LL-L--JFL7|L--7|F7LF7L----7LJF-7F7FJL---JLJLJL-7LJLJ|F--J|L7|LJLJLJ|L-7L7JL-JL-7||L-7L----7|JF7|L7F---JF-----------77LJF7F7-L7|JFJFJL7|
+|7.7J7|FJJ.FF-JL---JLJL-JL----7|F-JFJ|LJF7F7F7F7F7F-JF7F7||JF7|FJL-7F--7L-7L7|F7F7F-J|L7FJF---7|L-JLJFJ|F--7L7F--7F-7F-7L7F7|||L-7||FFFJ7.|7
+LFJL|FF7--F7L------7F------7F7LJ|F7L-JF7|||||LJ||LJF7|||LJL7|LJL-7J|L-7L--J||LJ|||L-7L7|L7L7F7LJF-7F-JFLJF-JFJL7-|L7||JL7LJLJLJF-JLJJJJL|-L|
+|.|.L-JJ7||L7F----7||F-7F77LJL--J|L--7|LJ||||F-JL--JLJLJF--JL7F7FJFJF7L7F7F7L-7|||77L7||FJL||L-7L7LJF-7F-J|FJF7L7L-J|L-7|F7F7F7|JLJ7|FJ..|7.
+FLLFJ7L-|-|FJL---7LJ|L7LJL--7F---JF-7||F7LJLJL7F7F-7F--7L-7F7||LJFJFJL7||LJL7FJLJL7F-JLJL-7LJF7L-JF7L7|L---JFJL7L77FJF-JLJLJLJLJ-FJ-|..|.|L-
+|7LJF|J.LFJ|F7F-7L-7L7L-7F-7LJF---JFJLJ|L----7||||.|L7FL--J|||L-7|FJ-LLJL-7FJL---7|L-----7L7FJL---JL-J|7F---JF7L7L7L-JF-------7|||FF7F-F-|J7
+|FJ-|JJ-LL7LJLJFJF7L-JF7LJ-L7FJ-F--JF7FJF----JLJ|L7|FJF--7FJ|L7FJ||F7F7F7FJ|F7F-7|L---7F-JFJ|F----7F-7L7L--7-|L7L-JF77|F------JJ.|L|L|JLL|-J
+7|L-L--.-FL---7L-J|F7FJL-7F7LJF7L---JLJFJF-----7L7|LJFJF-JL7|FJL-JLJLJ|||L7|||L7|L-7F-JL-7|LLJF---J|JL7L7F7L-JFJF7FJL7|L---7LF77FLF7F|.F7LFJ
+FJ-FJ-J7.F7F-7L--7|||L7F7LJL--JL------7L7|F----JJ|L-7L7L77FJLJF-------J||FJ|||.||-FJL7F7FJL-7|L7F7FJF7L7LJL---JFJLJF7||F---JFJL7F-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|||LJLJL7||F-JL7JJ|LJFJ7J
+7-F-JL7|FJ|L7|||F-J|||7LJL--JF-J||F7LJ|L7F7L7|L|L--7L7FJFJL-JL--7|L7FFJF-----JL7|F7JFJL7FJFJ.|L7FJ|F---7F-7LJL-----JLJF---7|LJ|F--J77L|LJL77
+|F7F-LLJL-J-||LJL-7|||F---7F7L-7|LJL--JFJ|L-JL7|F--JFJL7L---7F-7|L7|FJFJF---7F7|||L7|F7||FJF-JFJ|FJL--7|L7L--7F-------JF-7|L7J|L---77.L-|-|F
+J-L7JLJ-F---JL7F--J|LJL--7LJ|F7|L-----7|LL7F-7|||F7FJF-JF7F7||FJ|FJLJFJFL7F-J|||||FJLJ|LJL7L-7L7|L7F-7|L7L--7|L----7F--JFJL7L-JF--7L7JJJJFJ|
+JLJJ-|F-JF7F-7|L---JF7F--JF7LJ|L-----7||F7LJL|||LJ|L7||FJ|||LJL7||F--JFF-J|F7||||||F7J|F-7L--JFJL7|L7|L7L--7||F7F-7LJF7FJ7.L7F-JF7L7|F-JFJ-|
+J.|LFL|F-JLJ|LJF----J|L---JL-7L------JLJ||F7FJ||F-J7|L7L7LJL--7|LJL-7F7|F7||LJ||||LJL7||FJF--7L-7|L7||FJF77LJLJLJ7L--JLJF7F7|L--JL7LJJ--|-F-
+LFL-L.LJJLF---7L----7L---7F7JL-7F---7-F7||||L7LJ|-F7|FJ7L-7F7FJL7F--J||LJ||L7FJ||L--7|LJL7|F7L--JL7|||L-J|F7F----------7|LJ||F7F7FJLFJ7LF-7.
+.|.|--|L|JL7F7L----7L---7LJ|F77LJ7F-JFJ||LJL7L-7|FJ||L7F-7||LJF7|L7F7|L7FJ|FJL-J|F7FJL7F-J||L7F7F7||||F7FJ|LJF-----7F-7LJF-JLJLJLJFF7JL-L.|-
+|JF-JFJ7|7F|||F7F-7|F7F7L-7LJ|F7F7L7JL7|L7F-JF7|||FJ|FJL7|||F7|||FJ|||FJL7|L7F--J||L-7|L-7||FJ||||||||||L-JF7L--7F7LJJ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F-.L---LJ|.F77FL-7F-7|7LF|FJJ7||J|--.|LLL777LL7--J|FF|||.L|FJ.F---7..|L|.F|J
+J..7-L7.---FJJJL7F--|7.LJ7F7||.F77-L7-L-7FF-|J77|7FLJJ7|F..|F--7|LJ-JJ7L7JF-J-F7L||.||-7-||JLLL7JF.|.|FLLJ.JJL|JJFL-7JF777|JJFJ.LLF7|L7J-FJ|
+LF7.||||.|7..L||J|7FJ|.|JFL.LJFFFJ7JJ.L|L-L-J-F7J7F|F7-7|FF-|-|-7||.J.FJ|LJ.FLJJ|||-LJ.L7LJ-.L-LF7-FLJ7JLF7.|.||-F.7L-FJF7LL--77..F-F7||.L-.
+.L.L-F|F|||FFFLJ.L-7JF-|--J7.7--J--J7--7FF7LFJLJ-F--||LJJJL||FL-FJL7|.7FL.|FL.F--||J.JFF7-JJF|7.|JF-7--7J||LF-F-7.JJFJ|.777..|.7JJJ.7LFL-|77
+7JL|--JLL7.F-JJ.--|L--.|7-J.-JJJ.F---7-F-JL.J.L|-J-LJL-J-JLJ7..L|..L7-LL|----7J.LLJJ-LL-|.LFL7----J-LJL-FL-L-J|JJF-F|LJ7-JLLLJ-L.|JLJ.L|-LL.
diff --git a/2023/10-Pipe_Maze/second.hs b/2023/10-Pipe_Maze/second.hs
new file mode 100644
index 0000000..12651ac
--- /dev/null
+++ b/2023/10-Pipe_Maze/second.hs
@@ -0,0 +1,150 @@
+-- requires cabal install --lib megaparsec parser-combinators
+module Main (main) where
+
+import Control.Applicative.Permutations
+import Control.Monad (void, when)
+import Data.Char qualified as C
+import Data.Either
+import Data.Functor
+import Data.List qualified as L
+import Data.Map qualified as M
+import Data.Maybe
+import Data.Set qualified as S
+import Data.Vector qualified as V
+import Data.Void (Void)
+import Text.Megaparsec
+import Text.Megaparsec.Char
+
+import Debug.Trace
+
+exampleExpectedOutput = 4
+
+data Direction = N | S | E | W deriving (Eq, Show)
+data Tile = NS | NE | NW | EW | ES | WS | Floor | Start | Loop deriving (Eq, Show)
+type Line = V.Vector Tile
+type Input = V.Vector Line
+
+type Parser = Parsec Void String
+
+parseTile :: Parser Tile
+parseTile = char '|' $> NS
+ <|> char 'L' $> NE
+ <|> char 'J' $> NW
+ <|> char '-' $> EW
+ <|> char 'F' $> ES
+ <|> char '7' $> WS
+ <|> char '.' $> Floor
+ <|> char 'S' $> Start
+
+parseLine :: Parser Line
+parseLine = do
+ line <- some parseTile <* eol
+ return $ V.generate (length line) (line !!)
+
+parseInput' :: Parser Input
+parseInput' = do
+ line <- some parseLine <* eof
+ return $ V.generate (length line) (line !!)
+
+parseInput :: String -> IO Input
+parseInput filename = do
+ input <- readFile filename
+ case runParser parseInput' filename input of
+ Left bundle -> error $ errorBundlePretty bundle
+ Right input' -> return input'
+
+compatible :: Tile -> Direction -> Bool
+compatible NS N = True
+compatible NS S = True
+compatible NE S = True
+compatible NE W = True
+compatible NW S = True
+compatible NW E = True
+compatible EW E = True
+compatible EW W = True
+compatible ES W = True
+compatible ES N = True
+compatible WS E = True
+compatible WS N = True
+compatible _ _ = False
+
+type Position = (Int, Int)
+type Heading = (Position, Direction)
+data Where = Outside | Inside
+
+compute :: Input -> Int
+compute input = V.sum $ V.zipWith (count 0 False) inputWithStartReplaced inputLooped
+ where
+ count :: Int -> Bool -> Line -> Line -> Int
+ count i w line line' | V.length line == 0 = i
+ | u /= Loop = count (if w then i+1 else i) w r s
+ | t == NS = count i (not w) r s
+ | (t == NE && t'== NW) || (t == ES && t' == WS) = count i w r'' s'
+ | otherwise = count i (not w) r'' s'
+ where
+ (t, u) = (line V.! 0, line' V.!0)
+ (r, s) = (V.tail line, V.tail line')
+ r' = V.dropWhile (== EW) r
+ s' = V.drop (1 + V.length s - V.length r') s
+ t' = r' V.! 0
+ r'' = V.tail r'
+ inputWithStartReplaced = input V.// [(sy, (input V.! sy) V.// [(sx, startingPipe startn starte starts startw)])]
+ startingPipe Nothing Nothing _ _ = WS
+ startingPipe Nothing _ Nothing _ = EW
+ startingPipe Nothing _ _ Nothing = ES
+ startingPipe _ Nothing Nothing _ = NW
+ startingPipe _ Nothing _ Nothing = NS
+ startingPipe _ _ Nothing Nothing = NE
+ inputLooped = walk start input
+ walk :: Heading -> Input -> Input -- walk the loop, marking each point in the loop to a Loop tile
+ walk h@((x, y), _) i | tile (fst h) == Just Start = i'
+ | otherwise = walk h' i'
+ where
+ h' = step h
+ i' = i V.// [(y, (i V.! y) V.// [(x, Loop)])]
+ step :: Heading -> Heading
+ step (p@(x, y), N) | tile p == Just NS = ((x, y-1), N)
+ | tile p == Just ES = ((x+1, y), E)
+ | tile p == Just WS = ((x-1, y), W)
+ step (p@(x, y), S) | tile p == Just NS = ((x, y+1), S)
+ | tile p == Just NE = ((x+1, y), E)
+ | tile p == Just NW = ((x-1, y), W)
+ step (p@(x, y), E) | tile p == Just NW = ((x, y-1), N)
+ | tile p == Just EW = ((x+1, y), E)
+ | tile p == Just WS = ((x, y+1), S)
+ step (p@(x, y), W) | tile p == Just NE = ((x, y-1), N)
+ | tile p == Just EW = ((x-1, y), W)
+ | tile p == Just ES = ((x, y+1), S)
+ start = head $ catMaybes [startn, starte, starts, startw]
+ startn = nearStart (sx, sy-1) N
+ starts = nearStart (sx, sy+1) S
+ starte = nearStart (sx+1, sy) E
+ startw = nearStart (sx-1, sy) W
+ nearStart :: Position -> Direction -> Maybe Heading
+ nearStart p d = case tile p of
+ Just t -> if compatible t d then Just (p, d) else Nothing
+ Nothing -> Nothing
+ (sx, sy) = (x, y) -- start
+ where
+ hasNoStart :: Line -> Bool
+ hasNoStart = V.all (/= Start)
+ y = length $ V.takeWhile hasNoStart input
+ x = length $ V.takeWhile (/= Start) (input V.! y)
+ tile :: Position -> Maybe Tile
+ tile (x, y) = case input V.!? y of
+ Just line -> line V.!? x
+ Nothing -> Nothing
+
+main :: IO ()
+main = do
+ example <- parseInput "example3"
+ let exampleOutput = compute example
+ when (exampleOutput /= exampleExpectedOutput) (error $ "example failed: got " ++ show exampleOutput ++ " instead of " ++ show exampleExpectedOutput)
+ example4 <- parseInput "example4"
+ let exampleOutput4 = compute example4
+ when (exampleOutput4 /= 8) (error $ "example failed: got " ++ show exampleOutput4 ++ " instead of " ++ show 8)
+ example5 <- parseInput "example5"
+ let exampleOutput5 = compute example5
+ when (exampleOutput5 /= 10) (error $ "example failed: got " ++ show exampleOutput5 ++ " instead of " ++ show 10)
+ input <- parseInput "input"
+ print $ compute input