-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDay11.hs
35 lines (30 loc) · 1.21 KB
/
Day11.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
28
29
30
31
32
33
34
35
module AOC2017.Day11 (day11a, day11b) where
import AOC2017.Types (Challenge)
import Data.Char (isAlpha)
import Data.List (foldl')
import Data.List.Split (splitOn)
import Data.Maybe (fromJust)
import Math.Geometry.Grid (distance, neighbour)
import Math.Geometry.Grid.Hexagonal2 (UnboundedHexGrid(..))
import Math.Geometry.Grid.HexagonalInternal2 (HexDirection(..))
parse :: String -> [HexDirection]
parse = map (parseDir . filter isAlpha) . splitOn ","
where
parseDir = \case
"nw" -> Northwest
"n" -> North
"ne" -> Northeast
"se" -> Southeast
"s" -> South
"sw" -> Southwest
d -> error $ "Bad direction " ++ d
step :: (Int, Int) -> HexDirection -> (Int, Int)
step p = fromJust . neighbour UnboundedHexGrid p
day11a :: Challenge
day11a = show . distance UnboundedHexGrid (0,0)
. foldl' step (0,0)
. parse
day11b :: Challenge
day11b = show . maximum . map (distance UnboundedHexGrid (0,0))
. scanl step (0,0)
. parse