mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-10 06:40:47 +00:00
48 lines
813 B
Go
48 lines
813 B
Go
|
package two
|
||
|
|
||
|
import "fmt"
|
||
|
|
||
|
type point struct {
|
||
|
x int
|
||
|
y int
|
||
|
direction int
|
||
|
}
|
||
|
|
||
|
func (p *point) String() string {
|
||
|
return fmt.Sprintf("X: %d Y:%d Direction: %s", p.x, p.y, []string{"N", "E", "S", "W", "Obs"}[p.direction])
|
||
|
}
|
||
|
|
||
|
func (p *point) recalibrate() {
|
||
|
switch p.direction {
|
||
|
case N:
|
||
|
p.y++
|
||
|
case E:
|
||
|
p.x--
|
||
|
case S:
|
||
|
p.y--
|
||
|
case W:
|
||
|
p.x++
|
||
|
}
|
||
|
|
||
|
if p.direction == W {
|
||
|
p.direction = 0
|
||
|
} else {
|
||
|
p.direction++
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func nextPoint(current point) point {
|
||
|
switch current.direction {
|
||
|
case N:
|
||
|
return point{current.x, current.y - 1, current.direction}
|
||
|
case E:
|
||
|
return point{current.x + 1, current.y, current.direction}
|
||
|
case S:
|
||
|
return point{current.x, current.y + 1, current.direction}
|
||
|
case W:
|
||
|
return point{current.x - 1, current.y, current.direction}
|
||
|
default:
|
||
|
return point{}
|
||
|
}
|
||
|
}
|