From 3271b1f2a58ce5aeab544821209554b8af74188e Mon Sep 17 00:00:00 2001 From: Gattix Date: Tue, 5 Dec 2023 22:30:42 +0100 Subject: [PATCH] day5 part 2 dumb actually just werks, simply takes a while might write a better solution if I find the time --- 2023/day05/day05.hs | 6 ++++++ 1 file changed, 6 insertions(+) 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"