mirror of
https://github.com/onyx-and-iris/aoc2023.git
synced 2024-11-15 23:20:49 +00:00
38 lines
654 B
Go
38 lines
654 B
Go
|
package main
|
||
|
|
||
|
type coords struct {
|
||
|
X int
|
||
|
Y int
|
||
|
}
|
||
|
|
||
|
func newCoords(x, y int) coords {
|
||
|
return coords{X: x, Y: y}
|
||
|
}
|
||
|
|
||
|
type imager struct {
|
||
|
point coords
|
||
|
space []coords
|
||
|
}
|
||
|
|
||
|
// newImager returns an imager type
|
||
|
func newImager() *imager {
|
||
|
return &imager{point: newCoords(0, 0), space: make([]coords, 0)}
|
||
|
}
|
||
|
|
||
|
// add appends new coordinates to all points that describe the polygon
|
||
|
func (i *imager) add(direction string, count int) {
|
||
|
for j := 0; j < count; j++ {
|
||
|
switch direction {
|
||
|
case "U":
|
||
|
i.point.Y--
|
||
|
case "D":
|
||
|
i.point.Y++
|
||
|
case "L":
|
||
|
i.point.X--
|
||
|
case "R":
|
||
|
i.point.X++
|
||
|
}
|
||
|
i.space = append(i.space, newCoords(i.point.X, i.point.Y))
|
||
|
}
|
||
|
}
|