@AoKSolution object Day11 { val graph = MapParser { line -> val nodes = line.split(": ", " ") put(nodes.first(), nodes.drop(1)) } fun Map>.countPaths( start: String, end: String, cache: MutableMap = mutableMapOf() ): Long = cache.getOrPut(start) { if (start == end) 1 else get(start).orEmpty().sumOf { countPaths(it, end, cache) } } context(_: PuzzleInput) fun part1() = graph().countPaths("you", "out") context(_: PuzzleInput) fun part2() = graph { graph -> listOf("svr", "fft", "dac", "out") .zipWithNext { start, end -> graph.countPaths(start, end) } .reduce(Long::times) } }