sln_2023_05
Copyright(c) Eric Mertens 2023
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellNone
LanguageHaskell2010

Main

Description

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

Documentation

main :: IO () Source #

>>> :main
457535844
41222968

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.

type Interval = Box' 1 Source #

A one-dimensional cuboid

interval Source #

Arguments

:: Int

start

-> Int

length

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