Parsing tweaks.
[advent-of-code-19.git] / advent03 / src / advent03.hs
index ea2645ef7b4d9a3b82434b8913ac882006896808..c022a1bb98c5dc6fae2ea663ff64c8f70f57a406 100644 (file)
@@ -8,7 +8,7 @@ import Text.Megaparsec.Char
 import qualified Text.Megaparsec.Char.Lexer as L
 import qualified Control.Applicative as CA
 
-import Data.List (foldl')
+import Data.List (foldl', foldl1')
 import qualified Data.Map as M
 import Data.Map ((!))
 
@@ -56,9 +56,7 @@ shortestPaths crossings = minimum $ M.elems  crossings
 
 crossovers :: [Path] -> Visited
 crossovers travelledPaths = 
-      foldl' (M.intersectionWith (+))
-             (_visited $ head travelledPaths)
-             (map _visited $ drop 1 travelledPaths)
+      foldl1' (M.intersectionWith (+)) $ map _visited travelledPaths
 
 travelAllPaths :: [[Segment]] -> [Path]
 travelAllPaths = map travelPath
@@ -103,7 +101,7 @@ integer = lexeme L.decimal
 symb = L.symbol sc
 comma = symb ","
 
-wiresP = some pathP
+wiresP = many pathP
 pathP = segmentP `sepBy1` comma
 
 segmentP = segmentify <$> directionP <*> integer