-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
52 lines (45 loc) · 1.07 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const assert = require('assert');
const mine = require('./mine');
const mine2 = require('./mine2');
const displayHelper = (input) => {
const padding = input
.split('\n')
.map((line) => line
.split('')
.findIndex((value) => value !== ' '))
.sort((a, b) => b - a)[0];
return input
.split('\n')
.map((line) => line
.split('')
.slice(padding - 2, line.length)
.join(''))
.join('\n');
};
describe('Day 13: Mine Cart Madness', () => {
it('should determine the location of the first crash', () => {
const tracks = displayHelper(String.raw`
/->-\
| | /----\
| /-+--+-\ |
| | | | v |
\-+-/ \-+--/
\------/
`);
assert.strictEqual(mine(tracks), '7,3');
});
describe('Part Two', () => {
it('should determine the location of the last cart', () => {
const tracks = displayHelper(String.raw`
/>-<\
| |
| /<+-\
| | | v
\>+</ |
| ^
\<->/
`);
assert.strictEqual(mine2(tracks), '6,4');
});
});
});