From a415bf279ec158c7736a0a4654d461ffb337ecc2 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Sun, 12 Dec 2021 13:53:09 +0100 Subject: [PATCH] day(12): keep only count Signed-off-by: Matej Focko --- src/year2021/day12/Day12.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/year2021/day12/Day12.kt b/src/year2021/day12/Day12.kt index 4362477..756dd6e 100644 --- a/src/year2021/day12/Day12.kt +++ b/src/year2021/day12/Day12.kt @@ -7,9 +7,9 @@ fun findAllPaths( path: List, visited: Set, twiceVisited: Boolean -): Set { +): Int { if (path.last() == "end") { - return setOf(path.joinToString("-")) + return 1 } val neighbours = graph @@ -19,14 +19,14 @@ fun findAllPaths( return neighbours.map { (neighbour, newTwiceVisited) -> findAllPaths(graph, path + neighbour, visited + neighbour, newTwiceVisited) - }.fold(emptySet()) { acc, it -> acc + it } + }.fold(0, Int::plus) } fun part1(input: Map>): Int = - findAllPaths(input, listOf("start"), setOf("start"), true).size + findAllPaths(input, listOf("start"), setOf("start"), true) fun part2(input: Map>): Int = - findAllPaths(input, listOf("start"), setOf("start"), false).size + findAllPaths(input, listOf("start"), setOf("start"), false) fun main() { val sample = readGraph(12, "sample")