[TASK] Day 2 Part 2
This commit is contained in:
@@ -18,14 +18,27 @@ class Day2 {
|
|||||||
|
|
||||||
static part2(input: string[]): number {
|
static part2(input: string[]): number {
|
||||||
|
|
||||||
|
let depth = 0;
|
||||||
// TODO implement
|
let aim = 0;
|
||||||
return 0;
|
let x = 0;
|
||||||
|
for (const entry of input) {
|
||||||
|
|
||||||
|
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 {
|
private static readUnits(input: string): number {
|
||||||
return parseInt(input.substr(input.indexOf(' ') + 1));
|
return parseInt(input.substr(input.indexOf(" ") + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Day2;
|
export default Day2;
|
||||||
|
|||||||
Reference in New Issue
Block a user