Skip to content

Commit b9fa6d6

Browse files
committed
feat: day 22 wip
1 parent 06706c3 commit b9fa6d6

File tree

4 files changed

+72
-4
lines changed

4 files changed

+72
-4
lines changed

src/main/java/com/adventofcode/flashk/day12/GardenGroups.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public long solveB() {
4545
int sides = calculateRegionSides(gardenPlots);
4646
regionSides.put(gardenPlots.stream().findFirst().get().getRegionId(), sides);
4747
//price += regionAreas.get(gardenPlots.stream().findFirst().get().getRegionId()) * sides;
48-
//System.out.println(gardenPlots.stream().findFirst().get().getPlant()+" | "+sides);
48+
System.out.println(gardenPlots.stream().findFirst().get().getPlant()+" | "+sides);
4949
}
5050

5151
// TODO calculate sides of each region
@@ -84,8 +84,14 @@ private int calculateRegionSides(Set<GardenPlot> gardenPlots) {
8484
int internalConvexAngles = 0;
8585

8686
for(GardenPlot gardenPlot : gardenPlots) {
87-
externalAngles += sumExternalAngles(gardenPlot);
88-
internalAngles += sumInternalAngles(gardenPlot); // TODO descomenta esto para resultado final
87+
int currentExternalAngles = sumExternalAngles(gardenPlot);
88+
int currentInternalAngles = sumInternalAngles(gardenPlot); // Esto debería dar 1080 para el plot (2,2) ?
89+
//if(currentExternalAngles != 360 && currentInternalAngles != 1080) {
90+
externalAngles += currentExternalAngles;
91+
internalAngles += currentInternalAngles;
92+
//}
93+
94+
8995
internalConvexAngles += sumInternalConvexAngles(gardenPlot);
9096
}
9197

src/test/java/com/adventofcode/flashk/common/test/constants/TestDisplayName.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ private TestDisplayName() {}
4040
public static final String PART_2_SAMPLE_2 = "Part 2 - Sample 2";
4141
public static final String PART_2_SAMPLE_3 = "Part 2 - Sample 3";
4242
public static final String PART_2_SAMPLE_4 = "Part 2 - Sample 4";
43+
public static final String PART_2_SAMPLE_5 = "Part 2 - Sample 5";
44+
public static final String PART_2_SAMPLE_6 = "Part 2 - Sample 6";
4345
public static final String PART_2_DEBUG = "Part 2 - Debug";
4446

4547
public static final String PART_ONE_SINGLE_SAMPLE = "Part 1 - Single sample data";

src/test/java/com/adventofcode/flashk/common/test/constants/TestFilename.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ private TestFilename() {}
1212
public static final String INPUT_FILE_SINGLE_SAMPLE_2 = "single_sample_2.input";
1313
public static final String INPUT_FILE_SINGLE_SAMPLE_3 = "single_sample_3.input";
1414
public static final String INPUT_FILE_SINGLE_SAMPLE_4 = "single_sample_4.input";
15-
15+
public static final String INPUT_FILE_SINGLE_SAMPLE_5 = "single_sample_5.input";
16+
public static final String INPUT_FILE_SINGLE_SAMPLE_6 = "single_sample_6.input";
1617
// Other tests
1718
public static final String ARRAY_JSON = "array.json";
1819
public static final String INVALID_JSON = "invalid.json";

src/test/java/com/adventofcode/flashk/day12/Day12Test.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,64 @@ public void testSolvePart2SingleSample4() {
125125
assertEquals(368L,gardenGroups.solveB());
126126
}
127127

128+
@Test
129+
@Order(3)
130+
@Tag(TestTag.PART_2)
131+
@Tag(TestTag.SAMPLE)
132+
@DisplayName(TestDisplayName.PART_2_SAMPLE_5)
133+
public void testSolvePart2SingleSample5() {
134+
135+
// Reddit: [2024 Day 12] Another test case
136+
// https://www.reddit.com/r/adventofcode/s/Vxjv0Hf8J0
137+
138+
// Read input file
139+
char[][] inputs = Input.read2DCharArray(INPUT_FOLDER, TestFilename.INPUT_FILE_SINGLE_SAMPLE_5);
140+
GardenGroups gardenGroups = new GardenGroups(inputs);
141+
142+
// Should be:
143+
// A - 39 blocks - 22 fences
144+
// C - 2 blocks - 4 fences
145+
// B - 4 blocks - 4 fences
146+
// D - 2 blocks - 4 fences
147+
// B - 4 blocks - 4 fences
148+
// D - 5 blocks - 8 fences
149+
150+
// Región A explicada:
151+
// AAAAAAAA
152+
// AA.....A
153+
// AA...AAA
154+
// A..AAAAA
155+
// A..A...A
156+
// AAAA.A.A
157+
// AAAAAAAA
158+
//
159+
//
160+
// Filas exteriores: 4
161+
// Filas horizontales: 9
162+
// Filas verticales: 9
163+
//
164+
// Total = 4 + 9 + 9 = 22
165+
166+
assertEquals(946L, gardenGroups.solveB());
167+
}
168+
169+
@Test
170+
@Order(3)
171+
@Tag(TestTag.PART_2)
172+
@Tag(TestTag.SAMPLE)
173+
@DisplayName(TestDisplayName.PART_2_SAMPLE_6)
174+
public void testSolvePart2SingleSample6() {
175+
176+
// Reddit: [2024 Day 12 (Part 2)] I am losing my mind.
177+
// https://www.reddit.com/r/adventofcode/s/imxtVGMII2
178+
179+
// Read input file
180+
char[][] inputs = Input.read2DCharArray(INPUT_FOLDER, TestFilename.INPUT_FILE_SINGLE_SAMPLE_6);
181+
GardenGroups gardenGroups = new GardenGroups(inputs);
182+
183+
assertEquals(160L,gardenGroups.solveB());
184+
}
185+
128186
@Test
129187
@Order(4)
130188
@Tag(TestTag.PART_2)
@@ -138,6 +196,7 @@ public void testSolvePart2Input() {
138196
System.out.println("Solution: "+gardenGroups.solveB());
139197

140198
// 875718 -> Too high
199+
// 871792 -> Too high (tras ajustar lógica para los convexos internos.
141200
assertEquals(0L,0L);
142201

143202
}

0 commit comments

Comments
 (0)