Skip to content

Commit e55cc15

Browse files
committed
feat: Day 23: Experimental Emergency Teleportation (part 1)
1 parent 676251f commit e55cc15

File tree

5 files changed

+85
-1
lines changed

5 files changed

+85
-1
lines changed

Diff for: .github/badges/completion.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"schemaVersion": 1,
33
"label": "completion",
4-
"message": "35/50",
4+
"message": "36/50",
55
"color": "yellow"
66
}

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Collect stars by solving puzzles. Two puzzles will be made available on each day
3131
- [Day 15: Beverage Bandits](day-15-beverage-bandits/)
3232
- [Day 16: Chronal Classification](day-16-chronal-classification/)
3333
- [Day 18: Settlers of The North Pole](day-18-settlers-of-the-north-pole/)
34+
- [Day 23: Experimental Emergency Teleportation](day-23-experimental-emergency-teleportation/)
3435
- [Day 25: Four-Dimensional Adventure](day-25-four-dimensional-adventure/)
3536

3637
## Running Tests
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Day 23: Experimental Emergency Teleportation
2+
3+
Using your torch to search the darkness of the rocky cavern, you finally locate the man's friend: a small **reindeer**.
4+
5+
You're not sure how it got so far in this cave. It looks sick - too sick to walk - and too heavy for you to carry all the way back. Sleighs won't be invented for another 1500 years, of course.
6+
7+
The only option is **experimental emergency teleportation**.
8+
9+
You hit the "experimental emergency teleportation" button on the device and push **I accept the risk** on no fewer than 18 different warning messages. Immediately, the device deploys hundreds of tiny **nanobots** which fly around the cavern, apparently assembling themselves into a very specific **formation**. The device lists the `X,Y,Z` position (`pos`) for each nanobot as well as its **signal radius** (`r`) on its tiny screen (your puzzle input).
10+
11+
Each nanobot can transmit signals to any integer coordinate which is a distance away from it **less than or equal** to its signal radius (as measured by [Manhattan distance](https://en.wikipedia.org/wiki/Taxicab_geometry)). Coordinates a distance away of less than or equal to a nanobot's signal radius are said to be **in range** of that nanobot.
12+
13+
Before you start the teleportation process, you should determine which nanobot is the **strongest** (that is, which has the largest signal radius) and then, for that nanobot, the **total number of nanobots that are in range** of it, **including itself**.
14+
15+
For example, given the following nanobots:
16+
17+
```
18+
pos=<0,0,0>, r=4
19+
pos=<1,0,0>, r=1
20+
pos=<4,0,0>, r=3
21+
pos=<0,2,0>, r=1
22+
pos=<0,5,0>, r=3
23+
pos=<0,0,3>, r=1
24+
pos=<1,1,1>, r=1
25+
pos=<1,1,2>, r=1
26+
pos=<1,3,1>, r=1
27+
```
28+
29+
The strongest nanobot is the first one (position `0,0,0`) because its signal radius, `4` is the largest. Using that nanobot's location and signal radius, the following nanobots are in or out of range:
30+
- The nanobot at `0,0,0` is distance `0` away, and so it is **in range**.
31+
- The nanobot at `1,0,0` is distance `1` away, and so it is **in range**.
32+
- The nanobot at `4,0,0` is distance `4` away, and so it is **in range**.
33+
- The nanobot at `0,2,0` is distance `2` away, and so it is **in range**.
34+
- The nanobot at `0,5,0` is distance `5` away, and so it is **not** in range.
35+
- The nanobot at `0,0,3` is distance `3` away, and so it is **in range**.
36+
- The nanobot at `1,1,1` is distance `3` away, and so it is **in range**.
37+
- The nanobot at `1,1,2` is distance `4` away, and so it is **in range**.
38+
- The nanobot at `1,3,1` is distance `5` away, and so it is not **in range**.
39+
40+
In this example, in total, **`7`** nanobots are in range of the nanobot with the largest signal radius.
41+
42+
Find the nanobot with the largest signal radius. **How many nanobots are in range** of its signals?
43+
44+
## References
45+
- https://adventofcode.com/2018/day/23
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function distance(v0, v1) {
2+
return v0.reduce((sum, _, i) => sum + Math.abs(v0[i] - v1[i]), 0);
3+
}
4+
5+
module.exports = (input) => {
6+
const nanobots = input.split('\n').map((line) => {
7+
return {
8+
vector: /<(.*)>/.exec(line)[1].split(',').map((value) => parseInt(value)),
9+
radius: parseInt(/r=(\d+)/.exec(line)[1]),
10+
};
11+
});
12+
13+
const { vector, radius } = nanobots.sort((a, b) => b.radius - a.radius)[0];
14+
15+
return nanobots.reduce((numberInRange, { vector: otherVector }) => {
16+
return numberInRange + (distance(vector, otherVector) <= radius ? 1 : 0);
17+
}, 0);
18+
};

Diff for: day-23-experimental-emergency-teleportation/test.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const assert = require('assert');
2+
3+
const teleport = require('./teleport');
4+
5+
describe('Day 23: Experimental Emergency Teleportation', () => {
6+
it('should determine number of nanobots in range of strongest', () => {
7+
const nanobots =
8+
`pos=<0,0,0>, r=4
9+
pos=<1,0,0>, r=1
10+
pos=<4,0,0>, r=3
11+
pos=<0,2,0>, r=1
12+
pos=<0,5,0>, r=3
13+
pos=<0,0,3>, r=1
14+
pos=<1,1,1>, r=1
15+
pos=<1,1,2>, r=1
16+
pos=<1,3,1>, r=1`;
17+
18+
assert.strictEqual(teleport(nanobots), 7);
19+
});
20+
});

0 commit comments

Comments
 (0)