-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day25.hs
27 lines (21 loc) · 905 Bytes
/
Day25.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
-- Day 25: Four-Dimensional Adventure --
--
-- Usage: runhaskell Day25.hs < ../inputs/25.txt
import Data.Graph ( graphFromEdges
, components
)
import Data.List.Split ( splitOn )
type Coord = (Int, Int, Int, Int)
manhattanDist :: Coord -> Coord -> Int
manhattanDist (w, x, y, z) (w', x', y', z') =
abs (w - w') + abs (x - x') + abs (y - y') + abs (z - z')
parseCoord :: String -> Coord
parseCoord input = (read w, read x, read y, read z)
where [w, x, y, z] = splitOn "," input
part1 :: [Coord] -> Int
part1 coords = length $ components graph
where
(graph, _, _) = graphFromEdges [ edge x | x <- coords ]
edge x = (x, x, [ y | y <- coords, manhattanDist x y <= 3 ])
main :: IO ()
main = interact (show . part1 . map parseCoord . lines)