2024 Day 4 Complete!

This commit is contained in:
2024-12-04 08:14:00 -06:00
parent 9a8de11888
commit b852b3951a
6 changed files with 379 additions and 2 deletions

View File

@@ -26,24 +26,29 @@ 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) Add(o Coordinate) Coordinate {
return Coordinate{
X: c.X + o.X,
Y: c.Y + o.Y,
}
}
func (c Coordinate) Mul(by int) Coordinate {
return Coordinate{
X: c.X * by,
@@ -54,36 +59,46 @@ func (c Coordinate) Mul(by int) Coordinate {
func (c Coordinate) North() Coordinate {
return Coordinate{X: c.X, Y: c.Y - 1}
}
func (c Coordinate) East() Coordinate {
return Coordinate{X: c.X + 1, Y: c.Y}
}
func (c Coordinate) South() Coordinate {
return Coordinate{X: c.X, Y: c.Y + 1}
}
func (c Coordinate) West() Coordinate {
return Coordinate{X: c.X - 1, Y: c.Y}
}
func (c *Coordinate) NW() Coordinate {
return Coordinate{X: c.X - 1, Y: c.Y - 1}
}
func (c *Coordinate) NE() Coordinate {
return Coordinate{X: c.X + 1, Y: c.Y - 1}
}
func (c *Coordinate) SW() Coordinate {
return Coordinate{X: c.X - 1, Y: c.Y + 1}
}
func (c *Coordinate) SE() Coordinate {
return Coordinate{X: c.X + 1, Y: c.Y + 1}
}
func (c *Coordinate) GetOrthNeighbors() []Coordinate {
return []Coordinate{c.North(), c.East(), c.South(), c.West()}
}
func (c *Coordinate) GetAllNeighbors() []Coordinate {
return []Coordinate{
c.North(), c.NE(),
c.East(), c.SE(),
c.South(), c.SW(),
c.West(), c.NW()}
c.West(), c.NW(),
}
}
func (c *Coordinate) GetNorthCoord() *Coordinate {
@@ -92,18 +107,21 @@ func (c *Coordinate) GetNorthCoord() *Coordinate {
Y: c.Y - 1,
}
}
func (c *Coordinate) GetEastCoord() *Coordinate {
return &Coordinate{
X: c.X + 1,
Y: c.Y,
}
}
func (c *Coordinate) GetSouthCoord() *Coordinate {
return &Coordinate{
X: c.X,
Y: c.Y + 1,
}
}
func (c *Coordinate) GetWestCoord() *Coordinate {
return &Coordinate{
X: c.X - 1,
@@ -143,6 +161,7 @@ func (c Coordinate) Distance(t Coordinate) int {
func (c Coordinate) Equals(c2 Coordinate) bool {
return c.X == c2.X && c.Y == c2.Y
}
func (c Coordinate) Adjacent(c2 Coordinate) bool {
return c2.Equals(c.North()) ||
c2.Equals(c.NE()) ||
@@ -163,6 +182,7 @@ func GetHighestY(list ...Coordinate) int {
}
return top
}
func GetLowestY(list ...Coordinate) int {
bot := math.MaxInt
for i := range list {
@@ -172,6 +192,7 @@ func GetLowestY(list ...Coordinate) int {
}
return bot
}
func GetLowestX(list ...Coordinate) int {
bot := math.MaxInt
for i := range list {
@@ -181,6 +202,7 @@ func GetLowestX(list ...Coordinate) int {
}
return bot
}
func GetHighestX(list ...Coordinate) int {
top := math.MinInt
for i := range list {