this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Rewrite D01P01

modamo-gh ebf67b24 a47019ba

+33
+30
day01/part1.ts
··· 1 + import { copyFileSync, readFileSync } from "fs"; 2 + 3 + const instructions = readFileSync("./input.txt", "utf8") 4 + .split(/\n/) 5 + .map((line) => ({ 6 + direction: line[0], 7 + distance: Number(line.slice(1)) % 100 8 + })); 9 + 10 + let dialPosition = 50; 11 + let dialAtZero = 0; 12 + 13 + for (const { direction, distance } of instructions) { 14 + let newDialPosition = 15 + direction === "L" ? dialPosition - distance : dialPosition + distance; 16 + 17 + if (newDialPosition < 0) { 18 + dialPosition = 100 - (Math.abs(newDialPosition) % 100); 19 + } else if (newDialPosition > 99) { 20 + dialPosition = newDialPosition % 100; 21 + } else { 22 + dialPosition = newDialPosition; 23 + } 24 + 25 + if (dialPosition === 0) { 26 + dialAtZero++; 27 + } 28 + } 29 + 30 + console.log(dialAtZero);
+3
package.json
··· 1 + { 2 + "type": "module" 3 + }