+18
day1/day1.js
+18
day1/day1.js
···
1
+
const input = (await Bun.file("input.txt").text()).trim().split("\n")
2
+
3
+
const result = input.reduce(
4
+
([pos, part1, part2], x) => {
5
+
const dir = x[0] === "L" ? -1 : 1
6
+
const amount = +x.slice(1)
7
+
const new_pos = (((dir * amount + pos) % 100) + 100) % 100
8
+
const new_part1 = part1 + (new_pos === 0)
9
+
const new_part2 =
10
+
part2 +
11
+
parseInt((dir === -1 ? ((100 - pos) % 100) + amount : pos + amount) / 100)
12
+
return [new_pos, new_part1, new_part2]
13
+
},
14
+
[50, 0, 0],
15
+
)
16
+
17
+
console.log("Part 1:", result[1])
18
+
console.log("Part 2:", result[2])