From 3ffa8fac0fd50f32911d992bcefc10b0f2c6ed7c Mon Sep 17 00:00:00 2001 From: shu Date: Tue, 3 Dec 2019 08:17:42 +0100 Subject: [PATCH] day 3: small tweaks --- 2019/day3/day3.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/2019/day3/day3.hs b/2019/day3/day3.hs index 5eaf740..7016771 100644 --- a/2019/day3/day3.hs +++ b/2019/day3/day3.hs @@ -26,10 +26,11 @@ tracewire ((x,n):xs) (accx,accy) trc day3a :: [(Int,Int)] -> [(Int,Int)] -> Int day3a xs ys = Set.findMin $ Set.map manhattan (intersections xs ys) - where manhattan x = (abs $ fst x) + (abs $ snd x) + where manhattan (x,y) = abs x + abs y intersections :: [(Int,Int)] -> [(Int,Int)] -> Set.Set (Int, Int) intersections xs ys = Set.delete (0,0) crossset where crossset = (Set.fromList xs) `Set.intersection` (Set.fromList ys) -day3b xs ys = minimum [let f = fromJust . findIndex (==x) in f xs + f ys | x<-Set.toList $ intersections xs ys] +day3b xs ys = minimum [let f = fromJust . findIndex (==x) in f xs + f ys + | x<-Set.toList $ intersections xs ys]