11package de.havox_design.aoc2023.day25
22
3+ import org.jgrapht.Graph
4+ import org.jgrapht.alg.flow.GusfieldGomoryHuCutTree
5+ import org.jgrapht.graph.DefaultEdge
6+ import org.jgrapht.graph.SimpleGraph
7+
38class Day25 (private var filename : String ) {
9+ private val CONNECTING_DELIMITER = " : "
10+ private val ELEMENT_DELIMITER = " "
11+
412 fun solvePart1 (): Long =
5- 54L
13+ splitGroups(getResourceAsText(filename))
14+ .toLong()
615
716 fun solvePart2 (): Long =
817 0L
918
19+ private fun splitGroups (input : List <String >): Int {
20+ val graph: Graph <String , DefaultEdge > = SimpleGraph (DefaultEdge ::class .java)
21+
22+ for (row in input) {
23+ val split = row
24+ .split(CONNECTING_DELIMITER )
25+ val source = split[0 ]
26+ val destinationSplit = split[1 ]
27+ .split(ELEMENT_DELIMITER )
28+ .toMutableList()
29+
30+ graph.addVertex(source)
31+ for (destination in destinationSplit) {
32+ graph.addVertex(destination)
33+ graph.addEdge(source, destination)
34+ }
35+ }
36+
37+ val gusfieldGomoryHuCutTree = GusfieldGomoryHuCutTree (graph)
38+
39+ gusfieldGomoryHuCutTree.calculateMinCut()
40+
41+ val sourcePartition = gusfieldGomoryHuCutTree.sourcePartition
42+ val remainingPartitionSize = graph.vertexSet().size - sourcePartition.size
43+
44+ return remainingPartitionSize * sourcePartition.size
45+ }
46+
1047 private fun getResourceAsText (path : String ): List <String > =
1148 this .javaClass.classLoader.getResourceAsStream(path)!! .bufferedReader().readLines()
1249}
0 commit comments