Skip to content

Commit

Permalink
Simplify the while loop
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulWoitaschek committed Dec 23, 2024
1 parent db96174 commit 3cce8c4
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions 2024/src/main/kotlin/aoc/year2024/Day23.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@ object Day23 : Puzzle<Int, List<String>>(day = 23) {

override fun solvePart2(input: String): List<String> {
val lanPartyFinder = LanPartyFinder.parse(input)

var groups = lanPartyFinder.links
while (true) {
val newGroups = lanPartyFinder.addMoreConnections(groups)
if (newGroups.size == 1) {
return newGroups.single().sorted()
} else {
groups = newGroups
}
while (groups.size > 1) {
groups = lanPartyFinder.addMoreConnections(groups)
}
return groups.single().sorted()
}

private class LanPartyFinder(val links: Set<Set<String>>) {
Expand Down

0 comments on commit 3cce8c4

Please sign in to comment.