Skip to content

Commit

Permalink
Merge branch 'master' into feature/day_24
Browse files Browse the repository at this point in the history
  • Loading branch information
Flashky committed Dec 26, 2024
2 parents ef97b10 + fa1f977 commit 15cd5eb
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 36 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
- [Day 22 - Monkey Market](https://github.com/Flashky/advent-of-code-2024/tree/master/src/main/java/com/adventofcode/flashk/day22)
- [Day 23 - LAN Party](https://github.com/Flashky/advent-of-code-2024/tree/master/src/main/java/com/adventofcode/flashk/day23)
- [Day 24 - Crossed Wires](https://github.com/Flashky/advent-of-code-2024/tree/master/src/main/java/com/adventofcode/flashk/day24)
- [Day 25](https://github.com/Flashky/advent-of-code-2024/tree/master/src/main/java/com/adventofcode/flashk/day25)
- [Day 25 - Code Chronicle](https://github.com/Flashky/advent-of-code-2024/tree/master/src/main/java/com/adventofcode/flashk/day25)

## Cloning this repository

Expand Down
60 changes: 60 additions & 0 deletions src/main/java/com/adventofcode/flashk/day25/CodeChronicle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.adventofcode.flashk.day25;


import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class CodeChronicle {

private Set<Lock> locks = new HashSet<>();
private Set<Key> keys = new HashSet<>();

public CodeChronicle(List<String> inputs) {

int i = 0;
char[][] map = new char[7][5];
boolean isLock = false;

for(String row : inputs) {

if(i == 0) {
isLock = "#####".equals(row);
}

if(i == 7) {

if(isLock) {
locks.add(new Lock(map));
} else {
keys.add(new Key(map));
}

map = new char[7][5];
i = 0;

} else {
map[i++] = row.toCharArray();
}

}

if(isLock) {
locks.add(new Lock(map));
} else {
keys.add(new Key(map));
}
}

public long solveA() {
long count = 0;
for(Lock lock : locks) {
for(Key key :keys) {
if(lock.canFit(key)) {
count++;
}
}
}
return count;
}
}
22 changes: 22 additions & 0 deletions src/main/java/com/adventofcode/flashk/day25/Key.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.adventofcode.flashk.day25;

import com.adventofcode.flashk.common.Array2DUtil;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

public class Key {

@Getter
private final int[] heights = new int[5];

public Key(char[][] keyMap) {
char[][] transposedMap = Array2DUtil.transpose(keyMap);

for(int i = 0; i < transposedMap.length; i++) {
String rowValue = new String(transposedMap[i]);
heights[i] = StringUtils.countMatches(rowValue, "#")-1;
}
}


}
36 changes: 36 additions & 0 deletions src/main/java/com/adventofcode/flashk/day25/Lock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.adventofcode.flashk.day25;

import com.adventofcode.flashk.common.Array2DUtil;
import org.apache.commons.lang3.StringUtils;

public class Lock {

private final int[] pins = new int[5];

public Lock(char[][] lockMap) {

char[][] transposedMap = Array2DUtil.transpose(lockMap);

for(int i = 0; i < transposedMap.length; i++) {
String rowValue = new String(transposedMap[i]);
pins[i] = StringUtils.countMatches(rowValue, "#")-1;
}
}

public boolean canFit(Key key) {

boolean fit = true;
int[] heights = key.getHeights();
int i = 0;

while(fit && i < 5) {
int spaceLeft = 5 - pins[i];
if(spaceLeft < heights[i]){
fit = false;
}
i++;
}

return fit;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/adventofcode/flashk/day25/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Day 25:
# Day 25: Code Chronicle

[https://adventofcode.com/2024/day/25](https://adventofcode.com/2024/day/25)
42 changes: 8 additions & 34 deletions src/test/java/com/adventofcode/flashk/day25/Day25Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
import com.adventofcode.flashk.common.test.constants.TestFilename;
import com.adventofcode.flashk.common.test.constants.TestFolder;
import com.adventofcode.flashk.common.test.constants.TestTag;
import com.adventofcode.flashk.common.test.utils.PuzzleTest;
import com.adventofcode.flashk.common.test.utils.Input;

import static org.junit.jupiter.api.Assertions.assertEquals;

@DisplayName(TestDisplayName.DAY_25)
@TestMethodOrder(OrderAnnotation.class)
@Disabled // TODO Remove comment when implemented
public class Day25Test extends PuzzleTest {
class Day25Test {

private static final String INPUT_FOLDER = TestFolder.DAY_25;

Expand All @@ -31,55 +29,31 @@ public class Day25Test extends PuzzleTest {
@Tag(TestTag.PART_1)
@Tag(TestTag.SAMPLE)
@DisplayName(TestDisplayName.PART_1_SAMPLE)
public void testSolvePart1Sample() {
void part1SampleTest() {

// Read input file
List<String> inputs = Input.readStringLines(INPUT_FOLDER, TestFilename.INPUT_FILE_SAMPLE);

assertEquals(0L,0L);
CodeChronicle codeChronicle = new CodeChronicle(inputs);

assertEquals(3L, codeChronicle.solveA());
}

@Test
@Order(2)
@Tag(TestTag.PART_1)
@Tag(TestTag.INPUT)
@DisplayName(TestDisplayName.PART_1_INPUT)
public void testSolvePart1Input() {
void part1InputTest() {

// Read input file
List<String> inputs = Input.readStringLines(INPUT_FOLDER, TestFilename.INPUT_FILE);

System.out.println("Solution: ");
assertEquals(0L,0L);

}

@Test
@Order(3)
@Tag(TestTag.PART_2)
@Tag(TestTag.SAMPLE)
@DisplayName(TestDisplayName.PART_2_SAMPLE)
public void testSolvePart2Sample() {
CodeChronicle codeChronicle = new CodeChronicle(inputs);

// Read input file
List<String> inputs = Input.readStringLines(INPUT_FOLDER, TestFilename.INPUT_FILE_SAMPLE);
assertEquals(3320L,codeChronicle.solveA());

assertEquals(0L,0L);
}

@Test
@Order(4)
@Tag(TestTag.PART_2)
@Tag(TestTag.INPUT)
@DisplayName(TestDisplayName.PART_2_INPUT)
public void testSolvePart2Input() {

// Read input file
List<String> inputs = Input.readStringLines(INPUT_FOLDER, TestFilename.INPUT_FILE);

System.out.println("Solution: ");
assertEquals(0L,0L);

}

}

0 comments on commit 15cd5eb

Please sign in to comment.