Day15
Copyright(c) Eric Mertens 2021
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellNone
LanguageHaskell2010

Main

Description

https://adventofcode.com/2021/day/15

Finding the shortest route through a cave, and then finding the shortest route through a slightly larger cave.

This solution uses Djikstra's Algorithm to perform a shortest path search through the cave. (A* with a zero heuristic degenerates to this)

For part 2 this solution transforms the lookup coordinates rather than to build a larger cave array. The reason for this is to reduce memory pressure especially when running the search on much larger maps.

Synopsis

Documentation

main :: IO () Source #

>>> :main
698
3022

solve :: Coord -> (Coord -> Maybe Word8) -> Int Source #

Compute the risk score traveling through a cave.

extendCave :: UArray Coord Word8 -> (Coord, Coord -> Maybe Word8) Source #

Build a larger cave by tiling the input cave in a 5x5 grid. Added caves have their risk values updated according to their new locations.

fixRisk :: Word8 -> Word8 Source #

Risks are defined to roll over from 9 back to 1

>>> fixRisk <$> [1,5,9,10,12]
[1,5,9,1,3]