[TASK] Day 2 Part 2
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user