Skip to content

Commit 630d9d3

Browse files
committed
Advent of Code: solve 2025/01 (Go)
1 parent 1855a68 commit 630d9d3

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

advent_of_code.go/aoc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var puzzles = map[helpers.Puzzle]helpers.Solver{
2727
helpers.Puzzle{2024, 2}: y2024.New02(),
2828
helpers.Puzzle{2024, 3}: y2024.New03(),
2929
helpers.Puzzle{2024, 17}: y2024.New17(),
30+
helpers.Puzzle{2025, 1}: y2025.New01(),
3031
helpers.Puzzle{2025, 2}: y2025.New02(),
3132
}
3233

advent_of_code.go/y2025/01.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package y2025
2+
3+
import (
4+
"strconv"
5+
"strings"
6+
7+
"isaacgood.com/aoc/helpers"
8+
)
9+
10+
// Day01 solves 2025/01.
11+
type Day01 struct {
12+
turns [][2]int
13+
}
14+
15+
// New01 returns a new solver for 2025/01.
16+
func New01() *Day01 {
17+
return &Day01{}
18+
}
19+
20+
// SetInput handles input for this solver.
21+
func (p *Day01) SetInput(data string) {
22+
for line := range strings.SplitSeq(data, "\n") {
23+
turn := helpers.Atoi(line[1:])
24+
step := 1
25+
if line[0] == 'L' {
26+
step = -1
27+
}
28+
p.turns = append(p.turns, [2]int{turn, step})
29+
}
30+
}
31+
32+
// Solve returns the solution for one part.
33+
func (p *Day01) Solve(part int) string {
34+
var clicks uint64
35+
position := 50
36+
for _, turn := range p.turns {
37+
step := turn[1]
38+
for i := 0; i < turn[0]; i++ {
39+
position += step
40+
if position%100 == 0 && part == 1 {
41+
clicks++
42+
}
43+
}
44+
if position%100 == 0 && part == 0 {
45+
clicks++
46+
}
47+
}
48+
return strconv.FormatUint(clicks, 10)
49+
}

0 commit comments

Comments
 (0)