Skip to content

Commit fae98a3

Browse files
committed
Solve day 25 puzzle
1 parent 40c9e96 commit fae98a3

File tree

6 files changed

+64
-5
lines changed

6 files changed

+64
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
- [Day 22](https://github.com/Flashky/advent-of-code-2023/tree/master/src/main/java/com/adventofcode/flashk/day22)
2828
- [Day 23](https://github.com/Flashky/advent-of-code-2023/tree/master/src/main/java/com/adventofcode/flashk/day23)
2929
- [Day 24](https://github.com/Flashky/advent-of-code-2023/tree/master/src/main/java/com/adventofcode/flashk/day24)
30-
- [Day 25](https://github.com/Flashky/advent-of-code-2023/tree/master/src/main/java/com/adventofcode/flashk/day25)
30+
- [Day 25 - Snowverload](https://github.com/Flashky/advent-of-code-2023/tree/master/src/main/java/com/adventofcode/flashk/day25)
3131

3232
## Cloning this repository
3333

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
<artifactId>jgrapht-core</artifactId>
5353
<version>1.5.2</version>
5454
</dependency>
55+
<dependency>
56+
<groupId>org.jgrapht</groupId>
57+
<artifactId>jgrapht-ext</artifactId>
58+
<version>1.5.2</version>
59+
</dependency>
5560
<!-- JSON management -->
5661
<dependency>
5762
<groupId>com.fasterxml.jackson.core</groupId>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# Day 25
1+
# Day 25: Snowverload
22

33
[https://adventofcode.com/2023/day/25](https://adventofcode.com/2023/day/25)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.adventofcode.flashk.day25;
2+
3+
import org.apache.commons.lang3.StringUtils;
4+
import org.jgrapht.Graph;
5+
import org.jgrapht.alg.StoerWagnerMinimumCut;
6+
import org.jgrapht.graph.DefaultEdge;
7+
import org.jgrapht.graph.SimpleGraph;
8+
9+
import java.util.List;
10+
11+
public class Snowverload {
12+
13+
private final Graph<String, DefaultEdge> graph = new SimpleGraph<>(DefaultEdge.class);
14+
15+
public Snowverload(List<String> inputs) {
16+
17+
for(String input : inputs) {
18+
String[] inputParts = input.split(":");
19+
String leftVertex = inputParts[0];
20+
String[] rightVertexes = inputParts[1].stripLeading().split(StringUtils.SPACE);
21+
22+
graph.addVertex(leftVertex);
23+
for(String rightVertex : rightVertexes) {
24+
graph.addVertex(rightVertex);
25+
}
26+
}
27+
28+
}
29+
30+
public int solve() {
31+
32+
StoerWagnerMinimumCut<String,DefaultEdge> minCut = new StoerWagnerMinimumCut<>(graph);
33+
34+
int totalVertexes = graph.vertexSet().size();
35+
int cutSize = minCut.minCut().size();
36+
int remainingSize = totalVertexes - cutSize;
37+
38+
return cutSize * remainingSize;
39+
}
40+
41+
}

src/test/java/com/adventofcode/flashk/day25/Day25Test.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
import com.adventofcode.flashk.common.test.utils.Timer;
2020
import com.adventofcode.flashk.common.test.utils.Input;
2121

22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
2224
@DisplayName(TestDisplayName.DAY_25)
2325
@TestMethodOrder(OrderAnnotation.class)
24-
@Disabled // TODO Remove comment when implemented
2526
public class Day25Test extends PuzzleTest {
2627

2728
private final static String INPUT_FOLDER = TestFolder.DAY_25;
@@ -43,6 +44,12 @@ public void testSolvePart1Sample() {
4344

4445
// Read input file
4546
List<String> inputs = Input.readStringLines(INPUT_FOLDER, TestFilename.INPUT_FILE_SAMPLE);
47+
48+
Snowverload snowverload = new Snowverload(inputs);
49+
int result = snowverload.solve();
50+
51+
assertEquals(54, result);
52+
4653

4754
}
4855

@@ -57,14 +64,19 @@ public void testSolvePart1Input() {
5764

5865
// Read input file
5966
List<String> inputs = Input.readStringLines(INPUT_FOLDER, TestFilename.INPUT_FILE);
60-
67+
68+
Snowverload snowverload = new Snowverload(inputs);
69+
int result = snowverload.solve();
70+
71+
assertEquals(548960, result);
6172
}
6273

6374
@Test
6475
@Order(3)
6576
@Tag(TestTag.PART_TWO)
6677
@Tag(TestTag.SAMPLE)
6778
@DisplayName(TestDisplayName.PART_TWO_SAMPLE)
79+
@Disabled
6880
public void testSolvePart2Sample() {
6981

7082
System.out.print("2 | sample | ");
@@ -79,6 +91,7 @@ public void testSolvePart2Sample() {
7991
@Tag(TestTag.PART_TWO)
8092
@Tag(TestTag.INPUT)
8193
@DisplayName(TestDisplayName.PART_TWO_INPUT)
94+
@Disabled
8295
public void testSolvePart2Input() {
8396

8497
System.out.print("2 | input | ");

src/test/resources/inputs

0 commit comments

Comments
 (0)