2022 Day 14 Complete!
This commit is contained in:
@@ -18,6 +18,27 @@ func (c Coordinate) Relative(t Coordinate) Coordinate {
|
||||
return Coordinate{X: c.X + t.X, Y: c.Y + t.Y}
|
||||
}
|
||||
|
||||
func (c *Coordinate) MoveSouth() { c.Y++ }
|
||||
func (c *Coordinate) MoveNorth() { c.Y-- }
|
||||
func (c *Coordinate) MoveEast() { c.X++ }
|
||||
func (c *Coordinate) MoveWest() { c.X-- }
|
||||
func (c *Coordinate) MoveNE() {
|
||||
c.X++
|
||||
c.Y--
|
||||
}
|
||||
func (c *Coordinate) MoveSE() {
|
||||
c.X++
|
||||
c.Y++
|
||||
}
|
||||
func (c *Coordinate) MoveSW() {
|
||||
c.X--
|
||||
c.Y++
|
||||
}
|
||||
func (c *Coordinate) MoveNW() {
|
||||
c.X--
|
||||
c.Y--
|
||||
}
|
||||
|
||||
func (c Coordinate) North() Coordinate {
|
||||
return Coordinate{X: c.X, Y: c.Y - 1}
|
||||
}
|
||||
@@ -75,6 +96,9 @@ func CoordinateFromString(str string) *Coordinate {
|
||||
c := Coordinate{}
|
||||
r := strings.NewReader(str)
|
||||
_, err := fmt.Fscanf(r, "[%d, %d]", &c.X, &c.Y)
|
||||
if err != nil {
|
||||
_, err = fmt.Fscanf(r, "%d,%d", &c.X, &c.Y)
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user