day 3: small tweaks

This commit is contained in:
shu 2019-12-03 08:17:42 +01:00
parent b782929e01
commit 3ffa8fac0f

View File

@ -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]