Skip to content

Commit f96debc

Browse files
committed
2025 day01
1 parent 22c2842 commit f96debc

File tree

6 files changed

+114
-0
lines changed

6 files changed

+114
-0
lines changed

2025/day01/.bench

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +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}

2025/day01/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!-- You can add some comments here if you want to :D -->

2025/day01/main.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import (
4+
"container/ring"
5+
_ "embed"
6+
"os"
7+
)
8+
9+
//go:embed input.txt
10+
var input string
11+
12+
//go:embed input_test.txt
13+
var inputTest string
14+
15+
var r *ring.Ring
16+
17+
func init() {
18+
r = ring.New(100)
19+
n := r.Len()
20+
for i := 0; i < n; i++ {
21+
r.Value = i
22+
r = r.Next()
23+
}
24+
}
25+
26+
func main() {
27+
// Check argv if we use test input or not
28+
if len(os.Args) > 1 && os.Args[1] == "test" {
29+
input = inputTest
30+
}
31+
32+
answer := doPartOne(input)
33+
println(answer)
34+
35+
answer = doPartTwo(input)
36+
println(answer)
37+
}

2025/day01/main_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import "testing"
4+
5+
func BenchmarkPartOne(b *testing.B) {
6+
for n := 0; n < b.N; n++ {
7+
doPartOne(input)
8+
}
9+
}
10+
11+
func BenchmarkPartTwo(b *testing.B) {
12+
for n := 0; n < b.N; n++ {
13+
doPartTwo(input)
14+
}
15+
}

2025/day01/part1.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package main
2+
3+
import (
4+
"aocli/utils"
5+
"strings"
6+
)
7+
8+
func doPartOne(input string) int {
9+
lines := strings.Split(strings.TrimSpace(input), "\n")
10+
r = r.Move(50)
11+
ans := 0
12+
for _, line := range lines {
13+
num := utils.Atoi(line[1:])
14+
if line[0] == 'L' {
15+
num = -num
16+
}
17+
r = r.Move(num)
18+
if r.Value == 0 {
19+
ans++
20+
}
21+
}
22+
return ans
23+
}

2025/day01/part2.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import (
4+
"aocli/utils"
5+
"strings"
6+
)
7+
8+
func doPartTwo(input string) int {
9+
lines := strings.Split(strings.TrimSpace(input), "\n")
10+
r = r.Move(50)
11+
ans := 0
12+
for _, line := range lines {
13+
num := utils.Atoi(line[1:])
14+
for num > 100 {
15+
num -= 100
16+
ans++
17+
}
18+
if line[0] == 'L' {
19+
if r.Value.(int) > 0 && r.Value.(int)-num < 0 {
20+
ans++
21+
}
22+
r = r.Move(-num)
23+
if r.Value == 0 {
24+
ans++
25+
}
26+
continue
27+
}
28+
if r.Value.(int)+num > 100 {
29+
ans++
30+
}
31+
r = r.Move(num)
32+
if r.Value == 0 {
33+
ans++
34+
}
35+
}
36+
return ans
37+
}

0 commit comments

Comments
 (0)