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

Main

Description

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

Search around a cave visiting some caves more than others.

This solution makes the observation that we can optimize away all the big caves. Big caves can never be connected to other big caves or we'd have infinite cycles, and we don't need to track anything about visiting a big cave.

Synopsis

Documentation

main :: IO () Source #

>>> :main
3761
99138

toAdj :: [(Int, Int)] -> IntMap [Int] Source #

Compute directed edge map from a list of undirected edges.

compress :: IntMap [Int] -> IntMap (IntMap Int) Source #

Compute direct paths through a big cave to the next small cave.

start :: IntMap (IntMap Int) -> Bool -> Int Source #

Search the cave exploration given the directed edges and a flag if we're allowed to visit a small cave an extra time.

label :: [(String, String)] -> [(Int, Int)] Source #

Map all the cave names to integers. Use negative integers for big caves.