From e64af48b805c156d4f2f41a2807643668822070d Mon Sep 17 00:00:00 2001 From: shu Date: Wed, 4 Dec 2019 00:43:18 +0100 Subject: [PATCH] Fix solution 6ef036e2c5a actually made the solution incorrect, the list comprehension for part b relied on V 0 0 being in the list for the element to match the step number. The magic oneliner is rad tho so simply adjust the list comprehension. --- 2019/day3/day3.hs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/2019/day3/day3.hs b/2019/day3/day3.hs index 0bf0bbf..fea3e7e 100644 --- a/2019/day3/day3.hs +++ b/2019/day3/day3.hs @@ -28,8 +28,7 @@ day3a xs ys = Set.findMin $ Set.map manhattan (intersections xs ys) where manhattan (V2 x y) = abs x + abs y intersections :: [V2 Int] -> [V2 Int] -> Set.Set (V2 Int) -intersections xs ys = Set.delete (V2 0 0) crossset - where crossset = (Set.fromList xs) `Set.intersection` (Set.fromList ys) +intersections xs ys = (Set.fromList xs) `Set.intersection` (Set.fromList ys) -day3b xs ys = minimum [let f = fromJust . elemIndex x in +day3b xs ys = minimum [let f = succ . fromJust . elemIndex x in f xs + f ys | x<-Set.toList $ intersections xs ys]