diff --git a/2022/README.md b/2022/README.md index 5d69760de14156ffc973c835395eccb03b980bbf..256ce25ab2a8cf56ccc215a45f457d7dac057993 100644 --- a/2022/README.md +++ b/2022/README.md @@ -543,7 +543,28 @@ The subproblems are Since I created a `compareTo()` method as part of Part 1, Part 2 is easy. -## Day 1 +## Day 14 + +- [The problem](https://adventofcode.com/2022/day/14) +- [The solution](src/main/java/edu/unl/cse/bohn/year2022/Day14.java) + +### Part 1 + +The subproblems are +- Determine which locations are blocked +- Determine where a unit of sand moves to + - Can it move? + - Down, diagonally left, diagonally right? +- Determine the final status of a unit of sand + - Stationary, blocking a location + - Falling forever + +### Part 2 + +Same subproblems, except that falling forever isn't an option. +Instead, we'll have to pretend there's an infinitely-long floor. + +## Day 15 - [The problem](https://adventofcode.com/2022/day/14) - [The solution](src/main/java/edu/unl/cse/bohn/year2022/Day14.java) diff --git a/2022/src/main/java/edu/unl/cse/bohn/year2022/Day14.java b/2022/src/main/java/edu/unl/cse/bohn/year2022/Day14.java index d630b76f015076d019f8f67642c08a7d0ac2bb2b..f47010b492eff035ad849d60034cc56a930304b0 100644 --- a/2022/src/main/java/edu/unl/cse/bohn/year2022/Day14.java +++ b/2022/src/main/java/edu/unl/cse/bohn/year2022/Day14.java @@ -78,10 +78,10 @@ public class Day14 extends Puzzle { int firstArrowIndex = structure.indexOf(" -> "); int[] firstPoint = Arrays.stream(structure.substring(0, firstArrowIndex).strip().split(",")) .mapToInt(Integer::parseInt).toArray(); - String restOftheStructure = structure.substring(firstArrowIndex + " -> ".length()); - int endOfNextPointIndex = restOftheStructure.indexOf(" -> "); - endOfNextPointIndex = endOfNextPointIndex == -1 ? restOftheStructure.length() : endOfNextPointIndex; - int[] nextPoint = Arrays.stream(restOftheStructure.substring(0, endOfNextPointIndex).strip().split(",")) + String restOfTheStructure = structure.substring(firstArrowIndex + " -> ".length()); + int endOfNextPointIndex = restOfTheStructure.indexOf(" -> "); + endOfNextPointIndex = endOfNextPointIndex == -1 ? restOfTheStructure.length() : endOfNextPointIndex; + int[] nextPoint = Arrays.stream(restOfTheStructure.substring(0, endOfNextPointIndex).strip().split(",")) .mapToInt(Integer::parseInt).toArray(); int x = firstPoint[0]; int y = firstPoint[1]; @@ -92,7 +92,7 @@ public class Day14 extends Puzzle { if (y < nextPoint[1]) y++; if (y > nextPoint[1]) y--; } - block(restOftheStructure); + block(restOfTheStructure); } else { int[] coordinates = Arrays.stream(structure.strip().split(",")).mapToInt(Integer::parseInt).toArray(); block(coordinates[0], coordinates[1]);