mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-10 14:50:46 +00:00
45 lines
740 B
Go
45 lines
740 B
Go
|
package two
|
||
|
|
||
|
import (
|
||
|
"strings"
|
||
|
|
||
|
log "github.com/sirupsen/logrus"
|
||
|
)
|
||
|
|
||
|
type graph struct {
|
||
|
robot point
|
||
|
data []string
|
||
|
}
|
||
|
|
||
|
func newGraph() *graph {
|
||
|
return &graph{}
|
||
|
}
|
||
|
|
||
|
func (g *graph) String() string {
|
||
|
return strings.Join(g.data, "\n")
|
||
|
}
|
||
|
|
||
|
func (g *graph) valueAt(p point) rune {
|
||
|
return rune(g.data[p.y][p.x])
|
||
|
}
|
||
|
|
||
|
func (g *graph) updateRobot(dir direction) {
|
||
|
new := neighbours(g.robot)[dir]
|
||
|
log.Debugf("new robot point: %v", new)
|
||
|
|
||
|
g.updateEach(g.robot, '.')
|
||
|
g.updateEach(new, '@')
|
||
|
g.robot = new
|
||
|
}
|
||
|
|
||
|
func (g *graph) updateBox(p point, dir direction) {
|
||
|
new := neighbours(p)[dir]
|
||
|
|
||
|
g.updateEach(new, g.valueAt(p))
|
||
|
g.updateEach(p, '.')
|
||
|
}
|
||
|
|
||
|
func (g *graph) updateEach(p point, r rune) {
|
||
|
g.data[p.y] = replaceAtIndex(g.data[p.y], r, p.x)
|
||
|
}
|