This commit is contained in:
Jonas 2023-05-29 09:17:12 +02:00
parent 9e7f91a0be
commit 0a4e8cde6e
2 changed files with 1061 additions and 0 deletions

61
Day2/Submarine.ts Normal file
View File

@ -0,0 +1,61 @@
import { readLines } from "https://deno.land/std@0.177.1/io/read_lines.ts";
async function Part1() {
const file = await Deno.open("./Day2/input.txt");
let depth = 0;
let position = 0;
for await (const line of readLines(file)) {
const commands = line.split(" ");
switch(commands[0]) {
case "forward": {
position += +commands[1];
break;
}
case "down": {
depth += +commands[1];
break;
}
case "up": {
depth -= +commands[1];
break;
}
}
}
return position * depth;
}
async function Part2() {
const file = await Deno.open("./Day2/input.txt");
let depth = 0;
let position = 0;
let aim = 0;
for await (const line of readLines(file)) {
const commands = line.split(" ");
switch(commands[0]) {
case "forward": {
position += +commands[1];
depth += aim * +commands[1];
break;
}
case "down": {
aim += +commands[1];
break;
}
case "up": {
aim -= +commands[1];
break;
}
}
}
return position * depth;
}
console.log("Part1: " + await Part1());
console.log("Part1: " + await Part2());

1000
Day2/input.txt Normal file

File diff suppressed because it is too large Load Diff