summaryrefslogtreecommitdiff
path: root/day05
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2023-12-05 14:27:01 +0000
committerNat Lasseter <user@4574.co.uk>2023-12-05 14:27:01 +0000
commitc8c5a65d89fea8f61f20c03f0acac56b3440247a (patch)
treea18e939d95ca53312768f1c0e85cee06d85d90ee /day05
parent0e9a0e7332bc5ae4a4cd5a8c3cf6582cca339181 (diff)
Day 05 part 2 (slow and naïve)
Diffstat (limited to 'day05')
-rw-r--r--day05/day05.java23
1 files changed, 22 insertions, 1 deletions
diff --git a/day05/day05.java b/day05/day05.java
index d7d7992..4bbfb89 100644
--- a/day05/day05.java
+++ b/day05/day05.java
@@ -28,7 +28,28 @@ public class day05 {
}
public static String part2(RandomAccessFile input) throws IOException {
- return "WIP";
+ Garden garden = parseGarden(input);
+
+ long min_loc = Long.MAX_VALUE;
+ long start = -1;
+ long length = -1;
+ for (long seed: garden.seeds) {
+ if (start == -1) {
+ start = seed;
+ continue;
+ }
+ length = seed;
+
+ for(long s = start; s < start + length; s++) {
+ long loc = garden.location(s);
+ if (loc < min_loc) {
+ min_loc = loc;
+ }
+ }
+ start = -1;
+ }
+
+ return Long.toString(min_loc);
}
private static Garden parseGarden(RandomAccessFile input) throws IOException {