From: Neil Smith <neil.git@njae.me.uk>
Date: Tue, 3 Dec 2019 18:30:34 +0000 (+0000)
Subject: I remembered about foldl1 !
X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=52bfc1a213695ffc0a5107a0b1b7e094b5841423;p=advent-of-code-19.git

I remembered about foldl1 !
---

diff --git a/advent03/src/advent03.hs b/advent03/src/advent03.hs
index ea2645e..a863ffe 100644
--- a/advent03/src/advent03.hs
+++ b/advent03/src/advent03.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.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
diff --git a/advent03/src/advent03part1.hs b/advent03/src/advent03part1.hs
index 3702943..e2beb38 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