day5 part 2

dumb actually just werks, simply takes a while
might write a better solution if I find the time
This commit is contained in:
Gattix 2023-12-05 22:30:42 +01:00
parent fba7bef5d2
commit 3271b1f2a5

View File

@ -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"