[TASK] Day 2 Part 2

This commit is contained in:
2021-12-02 22:04:51 +01:00
parent c8b506f16e
commit 32f00ea017

View File

@@ -18,13 +18,26 @@ class Day2 {
static part2(input: string[]): number {
let depth = 0;
let aim = 0;
let x = 0;
for (const entry of input) {
// TODO implement
return 0;
if (entry.startsWith("up")) {
aim -= this.readUnits(entry);
} else if (entry.startsWith("down")) {
aim += this.readUnits(entry);
} else if (entry.startsWith("forward")) {
const movement = this.readUnits(entry);
depth += aim * movement;
x += movement;
}
}
return x * depth;
}
private static readUnits(input: string): number {
return parseInt(input.substr(input.indexOf(' ') + 1));
return parseInt(input.substr(input.indexOf(" ") + 1));
}
}