Skip to content

Commit 1f8fc7e

Browse files
committed
2025-day01 optimised
1 parent bd4c192 commit 1f8fc7e

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

2025/day01/.bench

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"Lines":[{"Name":"Part 1","N":2691,"NsPerOp":457758,"AllocedBytesPerOp":0,"AllocsPerOp":0,"MBPerS":0,"Measured":1,"Ord":0},{"Name":"Part 2","N":6332,"NsPerOp":192958,"AllocedBytesPerOp":0,"AllocsPerOp":0,"MBPerS":0,"Measured":1,"Ord":0}],"Measured":1}
1+
{"Lines":[{"Name":"Part 1","N":2703,"NsPerOp":439099,"AllocedBytesPerOp":0,"AllocsPerOp":0,"MBPerS":0,"Measured":1,"Ord":0},{"Name":"Part 2","N":6356,"NsPerOp":188973,"AllocedBytesPerOp":0,"AllocsPerOp":0,"MBPerS":0,"Measured":1,"Ord":0}],"Measured":1}

2025/day01/part1.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func doPartOne(input string) int {
1515
num = -num
1616
}
1717
r = r.Move(num)
18-
if r.Value == 0 {
18+
if r.Value.(int) == 0 {
1919
ans++
2020
}
2121
}

2025/day01/part2.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ import (
77

88
func doPartTwo(input string) int {
99
lines := strings.Split(strings.TrimSpace(input), "\n")
10-
r = r.Move(50)
10+
11+
// Calculate where we need to move to get to position 50
12+
// Since r.Value equals the position, we can calculate the offset
13+
currentPos := r.Value.(int)
14+
offset := (50 - currentPos + 100) % 100
15+
r = r.Move(offset)
16+
1117
ans := 0
1218
for _, line := range lines {
1319
num := utils.Atoi(line[1:])

0 commit comments

Comments
 (0)