From fc6ef766a57844d66b28515991d49d49d2e77b9f Mon Sep 17 00:00:00 2001 From: John Costa Date: Mon, 1 Dec 2025 19:28:15 +0000 Subject: [PATCH] 2025: Day 1 --- AdventOfCode2025/day1/index.ts | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 AdventOfCode2025/day1/index.ts diff --git a/AdventOfCode2025/day1/index.ts b/AdventOfCode2025/day1/index.ts new file mode 100644 index 0000000..0269aa0 --- /dev/null +++ b/AdventOfCode2025/day1/index.ts @@ -0,0 +1,38 @@ +const file = Bun.file("./input.txt"); +const content = await file.text(); + +const turns = content + .trim() + .split("\n") + .map((l) => Number(l[0] === "L" ? -1 : 1) * Number(l.slice(1))); + +let part1 = 0; +let part2 = 0; +let position = 50; + +for (const turn of turns) { + const effectiveTurn = turn % 100; + const boundToAdd = position === 0 ? 0 : 1; + + position += effectiveTurn; + + if (position > 99) { + position = position - 100; + part2 += boundToAdd; + } else if (position < 0) { + position = 100 + position; + part2 += boundToAdd; + } else if (position === 0) { + part2 += boundToAdd; + } + + const fullTurns = Math.floor(Math.abs(turn) / 100); + part2 += fullTurns; + + if (position === 0) { + part1++; + } +} + +console.log("Part 1: ", part1); +console.log("Part 2: ", part2);