From b9fa6d690dcb1c4eb347383559317c0fb74c9607 Mon Sep 17 00:00:00 2001 From: Flashky Date: Thu, 12 Dec 2024 17:22:59 +0100 Subject: [PATCH] feat: day 22 wip --- .../flashk/day12/GardenGroups.java | 12 +++- .../test/constants/TestDisplayName.java | 2 + .../common/test/constants/TestFilename.java | 3 +- .../adventofcode/flashk/day12/Day12Test.java | 59 +++++++++++++++++++ 4 files changed, 72 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/adventofcode/flashk/day12/GardenGroups.java b/src/main/java/com/adventofcode/flashk/day12/GardenGroups.java index 54dc15b..2e5a5c0 100644 --- a/src/main/java/com/adventofcode/flashk/day12/GardenGroups.java +++ b/src/main/java/com/adventofcode/flashk/day12/GardenGroups.java @@ -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 @@ -84,8 +84,14 @@ private int calculateRegionSides(Set 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); } diff --git a/src/test/java/com/adventofcode/flashk/common/test/constants/TestDisplayName.java b/src/test/java/com/adventofcode/flashk/common/test/constants/TestDisplayName.java index 07d735a..6c4ee47 100644 --- a/src/test/java/com/adventofcode/flashk/common/test/constants/TestDisplayName.java +++ b/src/test/java/com/adventofcode/flashk/common/test/constants/TestDisplayName.java @@ -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"; diff --git a/src/test/java/com/adventofcode/flashk/common/test/constants/TestFilename.java b/src/test/java/com/adventofcode/flashk/common/test/constants/TestFilename.java index f45ab71..7b30194 100644 --- a/src/test/java/com/adventofcode/flashk/common/test/constants/TestFilename.java +++ b/src/test/java/com/adventofcode/flashk/common/test/constants/TestFilename.java @@ -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"; diff --git a/src/test/java/com/adventofcode/flashk/day12/Day12Test.java b/src/test/java/com/adventofcode/flashk/day12/Day12Test.java index 93f648c..c9d45e1 100644 --- a/src/test/java/com/adventofcode/flashk/day12/Day12Test.java +++ b/src/test/java/com/adventofcode/flashk/day12/Day12Test.java @@ -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) @@ -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); }