Skip to content

Commit a3e1559

Browse files
committed
feat: Day 1: Chronal Calibration (part 1)
1 parent bb66707 commit a3e1559

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
# Advent of Code 2018 - My Solutions
22
[![Build Status](https://travis-ci.org/mariotacke/advent-of-code-2018.svg?branch=master)](https://travis-ci.org/mariotacke/advent-of-code-2018) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/mariotacke/advent-of-code-2018/master/LICENSE)
33

4-
TBA
4+
"We've detected some temporal anomalies," one of Santa's Elves at the Temporal Anomaly Research and Detection Instrument Station tells you. She sounded pretty worried when she called you down here. "At 500-year intervals into the past, someone has been changing Santa's history!"
5+
6+
"The good news is that the changes won't propagate to our time stream for another 25 days, and we have a device" - she attaches something to your wrist - "that will let you fix the changes with no such propagation delay. It's configured to send you 500 years further into the past every few days; that was the best we could do on such short notice."
7+
8+
"The bad news is that we are detecting roughly **fifty** anomalies throughout time; the device will indicate fixed anomalies with **stars**. The other bad news is that we only have one device and you're the best person for the job! Good lu--" She taps a button on the device and you suddenly feel like you're falling. To save Christmas, you need to get all **fifty stars** by December 25th.
9+
10+
Collect stars by solving puzzles. Two puzzles will be made available on each day in the advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants **one star**. Good luck!
511

612
## Days
713

8-
- [Day 1: ?](day-01-?/)
14+
- [Day 1: Chronal Calibration](day-01-chronal-calibration/)
915

1016
## Running Tests
1117

day-01-chronal-calibration/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Day 1: Chronal Calibration
2+
3+
After feeling like you've been falling for a few minutes, you look at the device's tiny screen. "Error: Device must be calibrated before first use. Frequency drift detected. Cannot maintain destination lock." Below the message, the device shows a sequence of changes in frequency (your puzzle input). A value like `+6` means the current frequency increases by `6`; a value like `-3` means the current frequency decreases by `3`.
4+
5+
For example, if the device displays frequency changes of `+1, -2, +3, +1`, then starting from a frequency of zero, the following changes would occur:
6+
7+
- Current frequency ` 0`, change of `+1`; resulting frequency ` 1`.
8+
- Current frequency ` 1`, change of `-2`; resulting frequency `-1`.
9+
- Current frequency `-1`, change of `+3`; resulting frequency ` 2`.
10+
- Current frequency ` 2`, change of `+1`; resulting frequency ` 3`.
11+
12+
In this example, the resulting frequency is `3`.
13+
14+
Here are other example situations:
15+
16+
- `+1, +1, +1` results in ` 3`
17+
- `+1, +1, -2` results in ` 0`
18+
- `-1, -2, -3` results in `-6`
19+
20+
Starting with a frequency of zero, **what is the resulting frequency** after all of the changes in frequency have been applied?
21+
22+
## References
23+
- https://adventofcode.com/2018/day/1
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const calibration = (input) => {
2+
return input
3+
.split('\n')
4+
.map((x) => parseInt(x))
5+
.reduce((a, b) => a + b, 0);
6+
};
7+
8+
module.exports = calibration;

day-01-chronal-calibration/test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const assert = require('assert');
2+
3+
const chronalCalibration = require('./chronal-calibration');
4+
5+
describe('Day 1: Chronal Calibration', () => {
6+
it('should calculate frequency from +1, -2, +3, +1', () => {
7+
const changes =
8+
`+1
9+
-2
10+
+3
11+
+1`;
12+
13+
assert.strictEqual(chronalCalibration(changes), 3);
14+
});
15+
16+
it('should calculate frequency from +1, +1, +1', () => {
17+
const changes =
18+
`+1
19+
+1
20+
+1`;
21+
22+
assert.strictEqual(chronalCalibration(changes), 3);
23+
});
24+
25+
it('should calculate frequency from +1, +1, -2', () => {
26+
const changes =
27+
`+1
28+
+1
29+
-2`;
30+
31+
assert.strictEqual(chronalCalibration(changes), 0);
32+
});
33+
34+
it('should calculate frequency from -1, -2, -3', () => {
35+
const changes =
36+
`-1
37+
-2
38+
-3`;
39+
40+
assert.strictEqual(chronalCalibration(changes), -6);
41+
});
42+
});

0 commit comments

Comments
 (0)