Files
advent-of-code-2023/day08/Part1.hs
2023-12-08 14:17:16 +01:00

14 lines
479 B
Haskell

module Part1 where
import Commons
import Data.HashMap.Strict ((!))
getDistance :: String -> String -> [Instruction] -> Network -> Int
getDistance start end [] network = getDistance start end (instructions network) network
getDistance start end (ih: t) network | start == end = 0
| otherwise = 1 + getDistance (nodes network ! (start, ih)) end t network
getDistanceToEnd :: Network -> Int
getDistanceToEnd = getDistance "AAA" "ZZZ" []