X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=advent03%2Fsrc%2Fadvent03part1.hs;h=5647ce5326d4c492cfdb6db4acf7195a862307e1;hb=c4794c207f6278f57aebedc5827d20cc6de41962;hp=370294337291358c8a86b55bb9b110b5f316e7f0;hpb=34400b8723ff60b5dc41593f273fcf6f45664363;p=advent-of-code-19.git diff --git a/advent03/src/advent03part1.hs b/advent03/src/advent03part1.hs index 3702943..5647ce5 100644 --- a/advent03/src/advent03part1.hs +++ b/advent03/src/advent03part1.hs @@ -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.Set as S import Linear (V2(..), (^+^), (^-^), (*^), (*^)) @@ -46,9 +46,7 @@ closest points = S.findMin $ S.map manhattan points crossovers :: [Path] -> Visited crossovers travelledPaths = - foldl' S.intersection - (_visited $ head travelledPaths) - (map _visited $ drop 1 travelledPaths) + foldl1' S.intersection $ map _visited travelledPaths travelAllPaths :: [[Segment]] -> [Path] travelAllPaths = map travelPath @@ -88,7 +86,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