Fix solution
6ef036e2c5
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.
This commit is contained in:
parent
e544fbb877
commit
e64af48b80
|
@ -28,8 +28,7 @@ day3a xs ys = Set.findMin $ Set.map manhattan (intersections xs ys)
|
||||||
where manhattan (V2 x y) = abs x + abs y
|
where manhattan (V2 x y) = abs x + abs y
|
||||||
|
|
||||||
intersections :: [V2 Int] -> [V2 Int] -> Set.Set (V2 Int)
|
intersections :: [V2 Int] -> [V2 Int] -> Set.Set (V2 Int)
|
||||||
intersections xs ys = Set.delete (V2 0 0) crossset
|
intersections xs ys = (Set.fromList xs) `Set.intersection` (Set.fromList ys)
|
||||||
where crossset = (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]
|
f xs + f ys | x<-Set.toList $ intersections xs ys]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user