Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
glguy committed Dec 6, 2023
1 parent ce12bbb commit 2751443
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions solutions/src/2023/05.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,11 @@ smallestDestination maps = lowerBound . minimum . concatMap (applyMaps maps)
-- assume the order is right. Transform the (destination, source, length)
-- parameters to a source interval and shift value.
checkMaps :: [(String, String, [(Int, Int, Int)])] -> [[(Interval, Int)]]
checkMaps input = foldr processMap finish input "seed"
checkMaps input = assert (froms == tos)
[[(interval src len, dst - src) | (dst, src, len) <- xs] | (_, _, xs) <- input]
where
processMap (from, to, entries) continue expect =
assert (expect == from) (map entryToInterval entries : continue to)

finish final = assert ("location" == final) []

entryToInterval (dst, src, len) = (interval src len, dst - src)
froms = [x | (x, _, _) <- input] ++ ["location"]
tos = "seed" : [x | (_, x, _) <- input]

-- | Apply the rewrite maps left to right to the input interval.
applyMaps :: [[(Interval, Int)]] -> Interval -> [Interval]
Expand Down

0 comments on commit 2751443

Please sign in to comment.