Copyright | (c) Eric Mertens 2023 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
https://adventofcode.com/2023/day/5
Given many layers of linear shifts of intervals we need to efficiently apply those shifts to a number of input ranges and find the lowest bound of the output intervals.
>>>
:{
:main + "seeds: 79 14 55 13 \nseed-to-soil map: 50 98 2 52 50 48 \nsoil-to-fertilizer map: 0 15 37 37 52 2 39 0 15 \nfertilizer-to-water map: 49 53 8 0 11 42 42 0 7 57 7 4 \nwater-to-light map: 88 18 7 18 25 70 \nlight-to-temperature map: 45 77 23 81 45 19 68 64 13 \ntemperature-to-humidity map: 0 69 1 1 0 69 \nhumidity-to-location map: 60 56 37 56 93 4 " :} 35 46
Synopsis
- main :: IO ()
- type IntervalRewriter = Map Int (Int, Int)
- smallestDestination :: [IntervalRewriter] -> [Interval] -> Int
- checkMaps :: [(String, String, [(Int, Int, Int)])] -> [IntervalRewriter]
- applyMaps :: [IntervalRewriter] -> Interval -> [Interval]
- applyMap :: IntervalRewriter -> Interval -> [Interval]
- type Interval = Box' 1
- interval :: Int -> Int -> Interval
- shiftInterval :: Int -> Interval -> Interval
- lowerBound :: Interval -> Int
- upperBound :: Interval -> Int
Documentation
type IntervalRewriter = Map Int (Int, Int) Source #
Map from lower-bound to (upper-bound, shift amount)
smallestDestination :: [IntervalRewriter] -> [Interval] -> Int Source #
Apply all the maps to all the intervals and return the smallest output
applyMaps :: [IntervalRewriter] -> Interval -> [Interval] Source #
Apply the rewrite maps left to right to the input interval.
applyMap :: IntervalRewriter -> Interval -> [Interval] Source #
Apply a single rewrite map to an input interval.
Construct an interval from a starting point and positive length
shiftInterval :: Int -> Interval -> Interval Source #
Modify the lower and upper bounds of an interval by a fixed amount.
lowerBound :: Interval -> Int Source #
Retrieve the inclusive lower-bound of an interval
upperBound :: Interval -> Int Source #
Retrieve the exclusive upper-bound of an interval