From 21b00821812236a67a358900bb7f3c9d46e00b05 Mon Sep 17 00:00:00 2001 From: Christopher Bohn <bohn@unl.edu> Date: Wed, 14 Dec 2022 09:18:32 -0600 Subject: [PATCH] Completed Year 2022 Day 14 --- 2022/README.md | 23 ++++++++++++++++++- .../java/edu/unl/cse/bohn/year2022/Day14.java | 10 ++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/2022/README.md b/2022/README.md index 5d69760..256ce25 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 d630b76..f47010b 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]); -- GitLab