mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2026-04-08 18:13:36 +00:00
add day-13 + benchmarks
This commit is contained in:
39
day-13/internal/machine/machine.go
Normal file
39
day-13/internal/machine/machine.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package machine
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Button struct {
|
||||
X int
|
||||
Y int
|
||||
}
|
||||
|
||||
type Prize struct {
|
||||
X int
|
||||
Y int
|
||||
}
|
||||
|
||||
type Machine struct {
|
||||
A Button
|
||||
B Button
|
||||
Prize Prize
|
||||
}
|
||||
|
||||
func New(btnA, btnB, prz []string) *Machine {
|
||||
return &Machine{
|
||||
A: Button{X: mustConv(btnA[2]), Y: mustConv(btnA[3])},
|
||||
B: Button{X: mustConv(btnB[2]), Y: mustConv(btnB[3])},
|
||||
Prize: Prize{X: mustConv(prz[1]), Y: mustConv(prz[2])},
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Machine) String() string {
|
||||
return fmt.Sprintf(
|
||||
"ButtonA: (%d,%d) ButtonB: (%d,%d) Prize: (%d,%d)",
|
||||
m.A.X,
|
||||
m.A.Y,
|
||||
m.B.X,
|
||||
m.B.Y,
|
||||
m.Prize.X,
|
||||
m.Prize.Y,
|
||||
)
|
||||
}
|
||||
11
day-13/internal/machine/util.go
Normal file
11
day-13/internal/machine/util.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package machine
|
||||
|
||||
import "strconv"
|
||||
|
||||
func mustConv(s string) int {
|
||||
n, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
Reference in New Issue
Block a user