-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5b5d54
commit 73ad92b
Showing
18 changed files
with
2,861 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# Day 25: Four-Dimensional Adventure | ||
The reindeer's symptoms are getting worse, and neither you nor the white-bearded man have a solution. At least the | ||
reindeer has a warm place to rest: a small bed near where you're sitting. | ||
|
||
As you reach down, the reindeer looks up at you, accidentally bumping a button on your wrist-mounted device with its | ||
nose in the process - a button labeled "**help**". | ||
|
||
"Hello, and welcome to the Time Travel Support Hotline! If you are lost in time and space, press 1. If you are trapped | ||
in a time paradox, press 2. If you need help caring for a sick reindeer, press 3. If you--" | ||
|
||
**Beep**. | ||
|
||
A few seconds later, you hear a new voice. "Hello; please state the nature of your reindeer." You try to describe the | ||
situation. | ||
|
||
"Just a moment, I think I can remotely run a diagnostic scan." A beam of light projects from the device and sweeps over | ||
the reindeer a few times. | ||
|
||
"Okay, it looks like your reindeer is very low on magical energy; it should fully recover if we can fix that. Let me | ||
check your timeline for a source.... Got one. There's actually a powerful source of magical energy about 1000 years | ||
forward from you, and at roughly your position, too! It looks like... hot chocolate? Anyway, you should be able to | ||
travel there to pick some up; just don't forget a mug! Is there anything else I can help you with today?" | ||
|
||
You explain that your device isn't capable of going forward in time. "I... see. That's tricky. Well, according to this | ||
information, your device should have the necessary hardware to open a small portal and send some hot chocolate back to | ||
you. You'll need a list of **fixed points in spacetime**; I'm transmitting it to you now." | ||
|
||
"You just need to align your device to the constellations of fixed points so that it can lock on to the destination and | ||
open the portal. Let me look up how much hot chocolate that breed of reindeer needs." | ||
|
||
"It says here that your particular reindeer is-- this can't be right, it says there's only one like that in the | ||
universe! But THAT means that you're--" You disconnect the call. | ||
|
||
The list of fixed points in spacetime (your puzzle input) is a set of four-dimensional coordinates. To align your | ||
device, acquire the hot chocolate, and save the reindeer, you just need to find the **number of constellations** of | ||
points in the list. | ||
|
||
Two points are in the same **constellation** if their manhattan distance apart is **no more than 3** or if they can form | ||
a chain of points, each a manhattan distance no more than 3 from the last, between the two of them. (That is, if a point | ||
is close enough to a constellation, it "joins" that constellation.) For example: | ||
``` | ||
0,0,0,0 | ||
3,0,0,0 | ||
0,3,0,0 | ||
0,0,3,0 | ||
0,0,0,3 | ||
0,0,0,6 | ||
9,0,0,0 | ||
12,0,0,0 | ||
``` | ||
In the above list, the first six points form a single constellation: | ||
|
||
`0,0,0,0` is exactly distance `3` from the next four, and the point at `0,0,0,6` is connected to the others by being `3` | ||
away from `0,0,0,3`, which is already in the constellation. The bottom two points, `9,0,0,0` and `12,0,0,0` are in a | ||
separate constellation because no point is close enough to connect them to the first constellation. So, in the above | ||
list, the number of constellations is **`2`**. (If a point at `6,0,0,0` were present, it would connect `3,0,0,0` and | ||
`9,0,0,0`, merging all of the points into a single giant constellation instead.) | ||
|
||
In this example, the number of constellations is `4`: | ||
``` | ||
-1,2,2,0 | ||
0,0,2,-2 | ||
0,0,0,-2 | ||
-1,2,0,0 | ||
-2,-2,-2,2 | ||
3,0,2,-1 | ||
-1,3,2,2 | ||
-1,0,-1,0 | ||
0,2,1,-2 | ||
3,0,0,0 | ||
``` | ||
In this one, it's `3`: | ||
``` | ||
1,-1,0,1 | ||
2,0,-1,0 | ||
3,2,-1,0 | ||
0,0,3,1 | ||
0,0,-1,-1 | ||
2,3,-2,0 | ||
-2,2,0,0 | ||
2,-2,0,-1 | ||
1,-1,0,-1 | ||
3,2,0,2 | ||
``` | ||
Finally, in this one, it's `8`: | ||
``` | ||
1,-1,-1,-2 | ||
-2,-2,0,1 | ||
0,2,1,3 | ||
-2,3,-2,1 | ||
0,2,3,-2 | ||
-1,-1,1,-2 | ||
0,-2,-1,0 | ||
-2,2,3,-1 | ||
1,2,2,0 | ||
-1,-2,0,-2 | ||
``` | ||
The portly man nervously strokes his white beard. It's time to get that hot chocolate. | ||
|
||
**How many constellations are formed by the fixed points in spacetime**? | ||
|
||
# Part Two | ||
A small glowing portal opens above the mug you prepared and just enough hot chocolate streams in to fill it. You suspect | ||
the reindeer has never encountered hot chocolate before, but seems to enjoy it anyway. You hope it works. | ||
|
||
It's time to start worrying about that **integer underflow in time itself** you | ||
[set up a few days ago](https://adventofcode.com/2018/day/21). You check the status of the device: "Insufficient chronal | ||
energy for activation. Energy required: **50 stars**." | ||
|
||
The reindeer bumps the device with its nose. | ||
|
||
"Energy required: **49 stars**." | ||
|
||
You have enough stars to **[Trigger the Underflow]**. | ||
|
||
You use all **fifty stars** to activate the underflow. As you begin to fall, the little reindeer looks up at you; its | ||
nose begins to glow red. | ||
|
||
You go back in time so far that you wrap around and end up back in your own time again! Oddly, history books contain | ||
some new details that you don't recognize... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
aoc2018/aoc2018-java/src/main/java/de/havox_design/aoc2018/day25/Day25.java
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
...18/aoc2018-java/src/main/java/de/havox_design/aoc2018/day25/FourDimensionalAdventure.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package de.havox_design.aoc2018.day25; | ||
|
||
import de.havox_design.aoc.utils.java.AoCFunctionality; | ||
|
||
import java.util.List; | ||
|
||
public class FourDimensionalAdventure implements AoCFunctionality { | ||
private final List<Position4d> positions; | ||
|
||
public FourDimensionalAdventure(String fileName) { | ||
PositionParser parser = new PositionParser(); | ||
List<String> input = readData(fileName); | ||
|
||
positions = input | ||
.stream() | ||
.map(parser::parseLine) | ||
.toList(); | ||
} | ||
|
||
public static long processTask1(String fileName) { | ||
FourDimensionalAdventure instance = new FourDimensionalAdventure(fileName); | ||
return instance.processTask1(); | ||
} | ||
|
||
public static String processTask2(String fileName) { | ||
FourDimensionalAdventure instance = new FourDimensionalAdventure(fileName); | ||
return instance.processTask2(); | ||
} | ||
|
||
public long processTask1() { | ||
int sizeMinus1 = positions.size() - 1; | ||
Integer[] parents = new Integer[positions.size()]; | ||
int constellations = positions.size(); | ||
|
||
for (int i = 0; i < sizeMinus1; i++) { | ||
for (int j = i + 1; j < positions.size(); j++) { | ||
if (positions.get(i).manhattanDistance(positions.get(j)) <= 3) { | ||
int iParent = getParent(parents, i); | ||
int jParent = getParent(parents, j); | ||
|
||
if (iParent != jParent) { | ||
parents[jParent] = iParent; | ||
constellations--; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return constellations; | ||
} | ||
|
||
public String processTask2() { | ||
return "Merry XMas!!!"; | ||
} | ||
|
||
private int getParent(final Integer[] parents, int i) { | ||
Integer parent = parents[i]; | ||
|
||
if (parent == null) { | ||
return i; | ||
} | ||
|
||
parent = getParent(parents, parent); | ||
parents[i] = parent; | ||
|
||
return parent; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
aoc2018/aoc2018-java/src/main/java/de/havox_design/aoc2018/day25/Position4d.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package de.havox_design.aoc2018.day25; | ||
|
||
public record Position4d(int x, int y, int z, int s) { | ||
public int manhattanDistance(Position4d other) { | ||
return Math.abs(x - other.x) + | ||
Math.abs(y - other.y) + | ||
Math.abs(z - other.z) + | ||
Math.abs(s - other.s); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
aoc2018/aoc2018-java/src/main/java/de/havox_design/aoc2018/day25/PositionParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package de.havox_design.aoc2018.day25; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class PositionParser { | ||
private static final String POSITION_PATTERN = "^(?<x>-?\\d+),\\s*(?<y>-?\\d+),\\s*(?<z>-?\\d+),\\s*(?<s>-?\\d+)$"; | ||
|
||
public Position4d parseLine(String line) { | ||
Pattern pattern = Pattern.compile(POSITION_PATTERN); | ||
Matcher matcher = pattern.matcher(line); | ||
|
||
if (matcher.matches()) { | ||
int x = Integer.parseInt(matcher.group("x").trim()); | ||
int y = Integer.parseInt(matcher.group("y").trim()); | ||
int z = Integer.parseInt(matcher.group("z").trim()); | ||
int s = Integer.parseInt(matcher.group("s").trim()); | ||
|
||
return new Position4d(x, y, z, s); | ||
} | ||
throw new IllegalArgumentException("Expected the input '" + line + "' to match pattern '" + POSITION_PATTERN + "'."); | ||
} | ||
} |
Oops, something went wrong.