Skip to content

Commit a2d265d

Browse files
committed
2025-day02 optimised (again)
1 parent d7e9cc8 commit a2d265d

File tree

2 files changed

+1
-13
lines changed

2 files changed

+1
-13
lines changed

2025/day02/.bench

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"Lines":[{"Name":"Part 1","N":50,"NsPerOp":23611500,"AllocedBytesPerOp":0,"AllocsPerOp":0,"MBPerS":0,"Measured":1,"Ord":0},{"Name":"Part 2","N":36,"NsPerOp":30616929,"AllocedBytesPerOp":0,"AllocsPerOp":0,"MBPerS":0,"Measured":1,"Ord":0}],"Measured":1}
1+
{"Lines":[{"Name":"Part 1","N":49,"NsPerOp":23892882,"AllocedBytesPerOp":0,"AllocsPerOp":0,"MBPerS":0,"Measured":1,"Ord":0},{"Name":"Part 2","N":39,"NsPerOp":31122533,"AllocedBytesPerOp":0,"AllocsPerOp":0,"MBPerS":0,"Measured":1,"Ord":0}],"Measured":1}

2025/day02/part2.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,7 @@ func doPartTwo(input string) int {
1616
idstring := strconv.Itoa(id)
1717
idlen := len(idstring)
1818

19-
// Single digit always matches
20-
if idlen == 1 {
21-
ans += id
22-
continue
23-
}
24-
2519
// Check if the number can be split into repeating chunks
26-
found := false
2720
for chunkSize := 1; chunkSize <= idlen/2; chunkSize++ {
2821
// Only check divisors of the length
2922
if idlen%chunkSize != 0 {
@@ -46,14 +39,9 @@ func doPartTwo(input string) int {
4639

4740
if match {
4841
ans += id
49-
found = true
5042
break
5143
}
5244
}
53-
54-
if found {
55-
continue
56-
}
5745
}
5846
}
5947
return ans

0 commit comments

Comments
 (0)