Skip to content
Snippets Groups Projects
Commit 21b00821 authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

Completed Year 2022 Day 14

parent 8a404b07
Branches main
No related tags found
No related merge requests found
...@@ -543,7 +543,28 @@ The subproblems are ...@@ -543,7 +543,28 @@ The subproblems are
Since I created a `compareTo()` method as part of Part 1, Part 2 is easy. 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 problem](https://adventofcode.com/2022/day/14)
- [The solution](src/main/java/edu/unl/cse/bohn/year2022/Day14.java) - [The solution](src/main/java/edu/unl/cse/bohn/year2022/Day14.java)
......
...@@ -78,10 +78,10 @@ public class Day14 extends Puzzle { ...@@ -78,10 +78,10 @@ public class Day14 extends Puzzle {
int firstArrowIndex = structure.indexOf(" -> "); int firstArrowIndex = structure.indexOf(" -> ");
int[] firstPoint = Arrays.stream(structure.substring(0, firstArrowIndex).strip().split(",")) int[] firstPoint = Arrays.stream(structure.substring(0, firstArrowIndex).strip().split(","))
.mapToInt(Integer::parseInt).toArray(); .mapToInt(Integer::parseInt).toArray();
String restOftheStructure = structure.substring(firstArrowIndex + " -> ".length()); String restOfTheStructure = structure.substring(firstArrowIndex + " -> ".length());
int endOfNextPointIndex = restOftheStructure.indexOf(" -> "); int endOfNextPointIndex = restOfTheStructure.indexOf(" -> ");
endOfNextPointIndex = endOfNextPointIndex == -1 ? restOftheStructure.length() : endOfNextPointIndex; endOfNextPointIndex = endOfNextPointIndex == -1 ? restOfTheStructure.length() : endOfNextPointIndex;
int[] nextPoint = Arrays.stream(restOftheStructure.substring(0, endOfNextPointIndex).strip().split(",")) int[] nextPoint = Arrays.stream(restOfTheStructure.substring(0, endOfNextPointIndex).strip().split(","))
.mapToInt(Integer::parseInt).toArray(); .mapToInt(Integer::parseInt).toArray();
int x = firstPoint[0]; int x = firstPoint[0];
int y = firstPoint[1]; int y = firstPoint[1];
...@@ -92,7 +92,7 @@ public class Day14 extends Puzzle { ...@@ -92,7 +92,7 @@ public class Day14 extends Puzzle {
if (y < nextPoint[1]) y++; if (y < nextPoint[1]) y++;
if (y > nextPoint[1]) y--; if (y > nextPoint[1]) y--;
} }
block(restOftheStructure); block(restOfTheStructure);
} else { } else {
int[] coordinates = Arrays.stream(structure.strip().split(",")).mapToInt(Integer::parseInt).toArray(); int[] coordinates = Arrays.stream(structure.strip().split(",")).mapToInt(Integer::parseInt).toArray();
block(coordinates[0], coordinates[1]); block(coordinates[0], coordinates[1]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment