Skip to content

Commit

Permalink
aoc 2024 day 11
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCK committed Dec 11, 2024
1 parent 6fc379e commit 5a4a7d2
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 17 deletions.
6 changes: 3 additions & 3 deletions adventofcode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@
[20232402tests]: src/test/java/org/ck/adventofcode/year2023/Day24Test.java
[20232501tests]: src/test/java/org/ck/adventofcode/year2023/Day25Test.java

# 2024 (20/49)
# 2024 (22/49)

| # | Name | Solution | Test |
|---------:|---------------------------------------------------|:------------------------------------:|:---------------------------------:|
Expand All @@ -1446,8 +1446,8 @@
| 20240902 | [Day 9: Disk Fragmenter - Part 2][20240902] | ✅[💾][20240902solution] | ✅[💾][20240902tests] |
| 20241001 | [Day 10: Hoof It][20241001] | ✅[💾][20241001solution] | ✅[💾][20241001tests] |
| 20241002 | [Day 10: Hoof It - Part 2][20241002] | ✅[💾][20241002solution] | ✅[💾][20241002tests] |
| 20241101 | [Day 11: ?][20241101] | [💾][20241101solution] | [💾][20241101tests] |
| 20241102 | [Day 11: ? - Part 2][20241102] | [💾][20241102solution] | [💾][20241102tests] |
| 20241101 | [Day 11: Plutonian Pebbles][20241101] | ✅[💾][20241101solution] | ✅[💾][20241101tests] |
| 20241102 | [Day 11: Plutonian Pebbles - Part 2][20241102] | ✅[💾][20241102solution] | ✅[💾][20241102tests] |
| 20241201 | [Day 12: ?][20241201] | [💾][20241201solution] | [💾][20241201tests] |
| 20241202 | [Day 12: ? - Part 2][20241202] | [💾][20241202solution] | [💾][20241202tests] |
| 20241301 | [Day 13: ?][20241301] | [💾][20241301solution] | [💾][20241301tests] |
Expand Down
63 changes: 52 additions & 11 deletions adventofcode/src/main/java/org/ck/adventofcode/year2024/Day11.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,75 @@
package org.ck.adventofcode.year2024;

import java.util.Scanner;
import java.util.*;
import org.ck.adventofcode.util.AOCSolution;
import org.ck.codechallengelib.annotation.Solution;

@Solution(
id = 20241101,
name = "Day 11: ?",
name = "Day 11: Plutonian Pebbles",
url = "https://adventofcode.com/2024/day/11",
category = "2024",
solved = false)
category = "2024")
@Solution(
id = 20241102,
name = "Day 11: ? - Part 2",
name = "Day 11: Plutonian Pebbles - Part 2",
url = "https://adventofcode.com/2024/day/11#part2",
category = "2024",
solved = false)
category = "2024")
public class Day11 extends AOCSolution {

@Override
protected void runPartOne(final Scanner in) {
run(in);
run(in, 25);
}

@Override
protected void runPartTwo(final Scanner in) {
run(in);
run(in, 75);
}

private void run(final Scanner in) {
print("Whoopsie");
private void run(final Scanner in, final int steps) {
final List<Long> numbers =
Arrays.stream(in.nextLine().split(" ")).map(Long::parseLong).toList();

final Map<String, Long> cache = new HashMap<>();
long sum = 0;

for (Long number : numbers) {
sum += getValueAfterSteps(cache, number, steps);
}

print(sum);
}

private long getValueAfterSteps(
final Map<String, Long> cache, final Long number, final int steps) {
final String key = "%d-%d".formatted(number, steps);
if (cache.containsKey(key)) {
return cache.get(key);
}

if (steps == 0) {
return 1;
}

long value = 0;

if (number == 0) {
value += getValueAfterSteps(cache, 1L, steps - 1);
} else {
final String baseTen = String.valueOf(number);

if (baseTen.length() % 2 == 0) {
value +=
getValueAfterSteps(
cache, Long.valueOf(baseTen.substring(0, baseTen.length() / 2)), steps - 1)
+ getValueAfterSteps(
cache, Long.valueOf(baseTen.substring(baseTen.length() / 2)), steps - 1);
} else {
value += getValueAfterSteps(cache, number * 2024, steps - 1);
}
}

cache.put(key, value);
return value;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package org.ck.adventofcode.year2024;

import org.ck.adventofcode.util.BaseAOCTest;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

@Disabled
class Day11Test extends BaseAOCTest {
@ParameterizedTest
@ValueSource(strings = {"01", "01a"})
Expand All @@ -14,7 +12,7 @@ void testOne(String name) throws Exception {
}

@ParameterizedTest
@ValueSource(strings = {"02", "02a"})
@ValueSource(strings = {"02"})
void testTwo(String name) throws Exception {
runTest(new Day11()::partTwo, "day11/%s".formatted(name));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
222461
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2 54 992917 5270417 2514 28561 0 990
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
55312
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
125 17
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
264350935776416
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2 54 992917 5270417 2514 28561 0 990
Empty file.
Empty file.

0 comments on commit 5a4a7d2

Please sign in to comment.