Files
advent-of-code-2025/internal/position/position.go
T

43 lines
757 B
Go
Raw Normal View History

// Package position provides types and functions to represent and manipulate positions and moves on a 2D grid.
package position
2025-12-18 14:04:21 -06:00
import (
"fmt"
"github.com/StevanFreeborn/advent-of-code-2025/internal/move"
)
2025-12-13 07:28:13 -06:00
type Position interface {
Row() int
Column() int
2025-12-13 07:28:13 -06:00
Move(move.Move) Position
}
type position struct {
row int
column int
}
func From(row int, column int) Position {
return position{
row: row,
column: column,
}
}
func (p position) Row() int {
return p.row
}
func (p position) Column() int {
return p.column
}
2025-12-13 07:28:13 -06:00
func (p position) Move(move move.Move) Position {
return From(p.row+move.NumberOfRows(), p.column+move.NumberOfColumns())
}
2025-12-18 14:04:21 -06:00
func (p position) String() string {
return fmt.Sprintf("c: %d r: %d", p.column, p.row)
}