Skip to content

Commit afdf257

Browse files
committed
Solved day25 part 1
1 parent 05e28ca commit afdf257

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44

55
// project meta data
66
group 'de.havox_design.aoc2023'
7-
version '0.24.3'
7+
version '0.24.4'
88

99
// Switch to gradle "all" distribution.
1010
wrapper {

day25/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ plugins {
88
dependencies {
99
implementation 'org.jetbrains.kotlin:kotlin-reflect'
1010
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
11+
implementation("org.jgrapht:jgrapht-core:1.5.2")
1112

1213
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.1'
1314
testImplementation 'org.jetbrains.kotlin:kotlin-test-junit'
Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,49 @@
11
package 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+
38
class 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

Comments
 (0)