diff --git a/2023/day05/day05.hs b/2023/day05/day05.hs index 8a9f3f5..2916be1 100644 --- a/2023/day05/day05.hs +++ b/2023/day05/day05.hs @@ -9,6 +9,7 @@ main = do input <- map (map words . lines) . splitOn "\n\n" <$> readFile "input" let (seeds, maps) = parse input print $ day5a maps seeds + print $ day5a maps (pairwise seeds) parse :: [[[String]]] -> ([Int], [SeedMap]) parse = parseSeeds &&& map parseMap . tail @@ -32,3 +33,8 @@ day5a :: [SeedMap] -> [Int] -> Int day5a maps = minimum . map f where f x = foldl applyMap x maps + +pairwise :: [Int] -> [Int] +pairwise [] = [] +pairwise (x:y:xs) = take y [x ..] ++ pairwise xs +pairwise _ = error "List length must be even"