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) }