Skip to content

Commit

Permalink
feat: day 22 wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Flashky committed Dec 12, 2024
1 parent 06706c3 commit b9fa6d6
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/main/java/com/adventofcode/flashk/day12/GardenGroups.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public long solveB() {
int sides = calculateRegionSides(gardenPlots);
regionSides.put(gardenPlots.stream().findFirst().get().getRegionId(), sides);
//price += regionAreas.get(gardenPlots.stream().findFirst().get().getRegionId()) * sides;
//System.out.println(gardenPlots.stream().findFirst().get().getPlant()+" | "+sides);
System.out.println(gardenPlots.stream().findFirst().get().getPlant()+" | "+sides);
}

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

for(GardenPlot gardenPlot : gardenPlots) {
externalAngles += sumExternalAngles(gardenPlot);
internalAngles += sumInternalAngles(gardenPlot); // TODO descomenta esto para resultado final
int currentExternalAngles = sumExternalAngles(gardenPlot);
int currentInternalAngles = sumInternalAngles(gardenPlot); // Esto debería dar 1080 para el plot (2,2) ?
//if(currentExternalAngles != 360 && currentInternalAngles != 1080) {
externalAngles += currentExternalAngles;
internalAngles += currentInternalAngles;
//}


internalConvexAngles += sumInternalConvexAngles(gardenPlot);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ private TestDisplayName() {}
public static final String PART_2_SAMPLE_2 = "Part 2 - Sample 2";
public static final String PART_2_SAMPLE_3 = "Part 2 - Sample 3";
public static final String PART_2_SAMPLE_4 = "Part 2 - Sample 4";
public static final String PART_2_SAMPLE_5 = "Part 2 - Sample 5";
public static final String PART_2_SAMPLE_6 = "Part 2 - Sample 6";
public static final String PART_2_DEBUG = "Part 2 - Debug";

public static final String PART_ONE_SINGLE_SAMPLE = "Part 1 - Single sample data";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ private TestFilename() {}
public static final String INPUT_FILE_SINGLE_SAMPLE_2 = "single_sample_2.input";
public static final String INPUT_FILE_SINGLE_SAMPLE_3 = "single_sample_3.input";
public static final String INPUT_FILE_SINGLE_SAMPLE_4 = "single_sample_4.input";

public static final String INPUT_FILE_SINGLE_SAMPLE_5 = "single_sample_5.input";
public static final String INPUT_FILE_SINGLE_SAMPLE_6 = "single_sample_6.input";
// Other tests
public static final String ARRAY_JSON = "array.json";
public static final String INVALID_JSON = "invalid.json";
Expand Down
59 changes: 59 additions & 0 deletions src/test/java/com/adventofcode/flashk/day12/Day12Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,64 @@ public void testSolvePart2SingleSample4() {
assertEquals(368L,gardenGroups.solveB());
}

@Test
@Order(3)
@Tag(TestTag.PART_2)
@Tag(TestTag.SAMPLE)
@DisplayName(TestDisplayName.PART_2_SAMPLE_5)
public void testSolvePart2SingleSample5() {

// Reddit: [2024 Day 12] Another test case
// https://www.reddit.com/r/adventofcode/s/Vxjv0Hf8J0

// Read input file
char[][] inputs = Input.read2DCharArray(INPUT_FOLDER, TestFilename.INPUT_FILE_SINGLE_SAMPLE_5);
GardenGroups gardenGroups = new GardenGroups(inputs);

// Should be:
// A - 39 blocks - 22 fences
// C - 2 blocks - 4 fences
// B - 4 blocks - 4 fences
// D - 2 blocks - 4 fences
// B - 4 blocks - 4 fences
// D - 5 blocks - 8 fences

// Región A explicada:
// AAAAAAAA
// AA.....A
// AA...AAA
// A..AAAAA
// A..A...A
// AAAA.A.A
// AAAAAAAA
//
//
// Filas exteriores: 4
// Filas horizontales: 9
// Filas verticales: 9
//
// Total = 4 + 9 + 9 = 22

assertEquals(946L, gardenGroups.solveB());
}

@Test
@Order(3)
@Tag(TestTag.PART_2)
@Tag(TestTag.SAMPLE)
@DisplayName(TestDisplayName.PART_2_SAMPLE_6)
public void testSolvePart2SingleSample6() {

// Reddit: [2024 Day 12 (Part 2)] I am losing my mind.
// https://www.reddit.com/r/adventofcode/s/imxtVGMII2

// Read input file
char[][] inputs = Input.read2DCharArray(INPUT_FOLDER, TestFilename.INPUT_FILE_SINGLE_SAMPLE_6);
GardenGroups gardenGroups = new GardenGroups(inputs);

assertEquals(160L,gardenGroups.solveB());
}

@Test
@Order(4)
@Tag(TestTag.PART_2)
Expand All @@ -138,6 +196,7 @@ public void testSolvePart2Input() {
System.out.println("Solution: "+gardenGroups.solveB());

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

}
Expand Down

0 comments on commit b9fa6d6

Please sign in to comment.