mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-10 06:40:47 +00:00
52 lines
854 B
Go
52 lines
854 B
Go
package one
|
|
|
|
import "fmt"
|
|
|
|
type coords struct {
|
|
X int
|
|
Y int
|
|
}
|
|
|
|
type point struct {
|
|
coords
|
|
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"}[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{coords{current.X, current.Y - 1}, current.direction}
|
|
case E:
|
|
return point{coords{current.X + 1, current.Y}, current.direction}
|
|
case S:
|
|
return point{coords{current.X, current.Y + 1}, current.direction}
|
|
case W:
|
|
return point{coords{current.X - 1, current.Y}, current.direction}
|
|
default:
|
|
return point{}
|
|
}
|
|
}
|