-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.js
33 lines (27 loc) · 740 Bytes
/
2.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
import input from "./input.js";
const moveSubMarine = (moves) => {
let aim = 0
let depth = 0
let xPosition = 0
for (const move of moves) {
let [ direction, value ] = move.split(' ')
value = parseInt(value)
if ('forward' === direction) {
xPosition += value
depth += aim * value
} else if ('up' === direction) {
aim -= value
} else if ('down' === direction) {
aim += value
}
}
return depth * xPosition
}
const output = moveSubMarine(input)
console.log({
title: 'Dive! [2.2]',
url: 'https://adventofcode.com/2021/day/2#part2',
inputPreview: input.slice(0, 5),
inputLength: input.length,
output,
})