Skip to content

Commit 7c83c31

Browse files
committed
chore(2025): start day 10 part 1
1 parent 2b5d282 commit 7c83c31

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-0
lines changed

go/2025/puzzles/day10/main.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/believer/aoc-utils/files"
8+
"github.com/believer/aoc-utils/utils"
9+
)
10+
11+
func main() {
12+
fmt.Println("Part 1: ", part1("input.txt"))
13+
fmt.Println("Part 2: ", part2("input.txt"))
14+
}
15+
16+
type Machine struct {
17+
lights []int
18+
buttons [][]int
19+
joltage []int
20+
}
21+
22+
func part1(name string) int {
23+
lines := files.ReadLines(name)
24+
var machines []Machine
25+
26+
for _, l := range lines {
27+
lights := strings.Split(l[1:], "] ")
28+
buttonSchema := strings.Split(lights[1], " {")
29+
buttonSchema = strings.Fields(buttonSchema[0])
30+
31+
lightSchema := make([]int, len(lights[0]))
32+
var buttons [][]int
33+
34+
for _, b := range buttonSchema {
35+
// Remove parenthesis
36+
b = b[1:]
37+
b = b[:len(b)-1]
38+
39+
// Create a matrix for the button presses
40+
buttonsSchema := make([]int, len(lightSchema))
41+
42+
for b := range strings.SplitSeq(b, ",") {
43+
button := utils.MustIntFromString(b)
44+
buttonsSchema[button] = 1
45+
}
46+
47+
buttons = append(buttons, buttonsSchema)
48+
}
49+
50+
machines = append(machines, Machine{
51+
lights: lightSchema,
52+
buttons: buttons,
53+
})
54+
}
55+
56+
for _, m := range machines[:1] {
57+
solveMachine(m)
58+
}
59+
60+
return 0
61+
}
62+
63+
func part2(name string) int {
64+
return 0
65+
}
66+
67+
// Gauss elimination
68+
func solveMachine(m Machine) int {
69+
N := len(m.lights)
70+
M := len(m.buttons)
71+
72+
// Create the augmented matrix [A|B]
73+
augmentedMatrix := make([][]int, N)
74+
for i := range N {
75+
augmentedMatrix[i] = make([]int, M+1)
76+
77+
// Copy A (buttons)
78+
for j := range M {
79+
augmentedMatrix[i][j] = m.buttons[j][i]
80+
}
81+
82+
// Copy B (lights)
83+
augmentedMatrix[i][M] = m.lights[i]
84+
}
85+
86+
fmt.Println(augmentedMatrix)
87+
88+
return 0
89+
}

go/2025/puzzles/day10/main_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestPart1(t *testing.T) {
10+
t.Run("Part 1", func(t *testing.T) {
11+
expected := 7
12+
actual := part1("test-input.txt")
13+
assert.Equal(t, expected, actual)
14+
})
15+
}
16+
17+
func TestPart2(t *testing.T) {
18+
t.Run("Part 2", func(t *testing.T) {
19+
expected := 0
20+
actual := part2("test-input.txt")
21+
assert.Equal(t, expected, actual)
22+
})
23+
}
24+
25+
func BenchmarkPart1(b *testing.B) {
26+
for b.Loop() {
27+
part1("input.txt")
28+
}
29+
}
30+
31+
func BenchmarkPart2(b *testing.B) {
32+
for b.Loop() {
33+
part2("input.txt")
34+
}
35+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[.##.] (3) (1,3) (2) (2,3) (0,2) (0,1) {3,5,4,7}
2+
[...#.] (0,2,3,4) (2,3) (0,4) (0,1,2) (1,2,3,4) {7,5,12,7,2}
3+
[.###.#] (0,1,2,3,4) (0,3,4) (0,1,2,4,5) (1,2) {10,11,11,5,10,5}

0 commit comments

Comments
 (0)