Code for the Advent of Code event
aoc advent-of-code
at rust 30 lines 534 B view raw
1#!/usr/bin/env -S deno run --allow-read 2 3const instructions = Deno.readTextFileSync("input").trim() 4 .split("\n").map( 5 (l) => l.split(" "), 6 ).map(([d, n]) => [d, parseInt(n)] as const); 7 8let position = 0; 9let aim = 0; 10let depth = 0; 11 12for (const [dir, n] of instructions) { 13 switch (dir) { 14 case "forward": 15 position += n; 16 depth += aim * n; 17 break; 18 19 case "down": 20 aim += n; 21 break; 22 23 case "up": 24 aim -= n; 25 break; 26 } 27} 28 29console.log(position * aim); 30console.log(position * depth);