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:
parent
fba7bef5d2
commit
3271b1f2a5
@ -9,6 +9,7 @@ main = do
|
|||||||
input <- map (map words . lines) . splitOn "\n\n" <$> readFile "input"
|
input <- map (map words . lines) . splitOn "\n\n" <$> readFile "input"
|
||||||
let (seeds, maps) = parse input
|
let (seeds, maps) = parse input
|
||||||
print $ day5a maps seeds
|
print $ day5a maps seeds
|
||||||
|
print $ day5a maps (pairwise seeds)
|
||||||
|
|
||||||
parse :: [[[String]]] -> ([Int], [SeedMap])
|
parse :: [[[String]]] -> ([Int], [SeedMap])
|
||||||
parse = parseSeeds &&& map parseMap . tail
|
parse = parseSeeds &&& map parseMap . tail
|
||||||
@ -32,3 +33,8 @@ day5a :: [SeedMap] -> [Int] -> Int
|
|||||||
day5a maps = minimum . map f
|
day5a maps = minimum . map f
|
||||||
where
|
where
|
||||||
f x = foldl applyMap x maps
|
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"
|
||||||
|
Loading…
Reference in New Issue
Block a user