From ff44a85cce927be9b930581bb698a3527500e922 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Thu, 2 Dec 2021 08:40:06 -0600 Subject: [PATCH] Day 2 done --- 2021/2.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/2021/2.ts b/2021/2.ts index 0ac231f..e3cb375 100644 --- a/2021/2.ts +++ b/2021/2.ts @@ -20,7 +20,26 @@ export function part1(input: string[]): number { await measureDuration(() => console.log("Part 1", part1(input))); export function part2(input: string[]): number { - return 0; + let x = 0; + let y = 0; + let aim = 0; + for (const line of input) { + console.log(line); + if (line.startsWith("forward ")) { + const arg = parseInt(line.substr(8)); + x += arg; + y += aim * arg; + } else if (line.startsWith("up ")) { + const arg = parseInt(line.substr(3)); + aim -= arg; + // y -= arg; + } else if (line.startsWith("down ")) { + const arg = parseInt(line.substr(5)); + aim += arg; + // y += arg; + } + } + return x * y; } await measureDuration(() => console.log("Part 2", part2(input)));