2024 Day 4 Complete!
This commit is contained in:
@@ -49,9 +49,11 @@ func StringSliceToCoordByteMap(input []string) CoordByteMap {
|
||||
func (m *CoordByteMap) RowCount() int {
|
||||
return m.BRY - m.TLY
|
||||
}
|
||||
|
||||
func (m *CoordByteMap) ColCount() int {
|
||||
return m.BRX - m.TLX
|
||||
}
|
||||
|
||||
func (m *CoordByteMap) GetRow(y int) []byte {
|
||||
if m.Repeats {
|
||||
y = (y + m.BRY) % m.BRY
|
||||
@@ -62,6 +64,7 @@ func (m *CoordByteMap) GetRow(y int) []byte {
|
||||
}
|
||||
return resp
|
||||
}
|
||||
|
||||
func (m *CoordByteMap) GetCol(x int) []byte {
|
||||
if m.Repeats {
|
||||
x = (x + m.BRX) % m.BRX
|
||||
@@ -72,12 +75,14 @@ func (m *CoordByteMap) GetCol(x int) []byte {
|
||||
}
|
||||
return resp
|
||||
}
|
||||
|
||||
func (m *CoordByteMap) AddRow(row []byte) {
|
||||
y := m.BRY + 1
|
||||
for x := 0; x < len(row); x++ {
|
||||
m.Put(Coordinate{X: x + m.TLX, Y: y}, row[x])
|
||||
}
|
||||
}
|
||||
|
||||
func (m *CoordByteMap) AddCol(col []byte) {
|
||||
x := m.BRX + 1
|
||||
for y := 0; y < len(col); y++ {
|
||||
@@ -142,9 +147,11 @@ func (m *CoordByteMap) Delete(pos Coordinate) {
|
||||
func (m *CoordByteMap) Height() int {
|
||||
return m.BRY - m.TLY
|
||||
}
|
||||
|
||||
func (m *CoordByteMap) Width() int {
|
||||
return m.BRX - m.TLX
|
||||
}
|
||||
|
||||
func (m *CoordByteMap) ReplaceAll(o, n byte) {
|
||||
for y := m.TLY; y <= m.BRY; y++ {
|
||||
for x := m.TLX; x <= m.BRX; x++ {
|
||||
@@ -238,7 +245,7 @@ func (m *CoordByteMap) FindFirst(b byte) (Coordinate, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return Coordinate{}, errors.New("Not Found")
|
||||
return Coordinate{}, errors.New("not found")
|
||||
}
|
||||
|
||||
// FindLast searches right to left, bottom to top for the last
|
||||
@@ -355,18 +362,21 @@ func (m *CoordByteMap) GrowNorth(size int, val byte) {
|
||||
m.Put(Coordinate{X: x, Y: tlY}, val)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *CoordByteMap) GrowEast(size int, val byte) {
|
||||
brX := m.BRX + 1
|
||||
for y := m.TLY; y <= m.BRY; y++ {
|
||||
m.Put(Coordinate{X: brX, Y: y}, val)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *CoordByteMap) GrowSouth(size int, val byte) {
|
||||
tlY := m.BRY + 1
|
||||
for x := m.TLX; x <= m.BRX; x++ {
|
||||
m.Put(Coordinate{X: x, Y: tlY}, val)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *CoordByteMap) GrowWest(size int, val byte) {
|
||||
brX := m.TLX - 1
|
||||
for y := m.TLY; y <= m.BRY; y++ {
|
||||
@@ -396,6 +406,7 @@ func (m CoordByteMap) Map(l func(c Coordinate, in byte) byte) CoordByteMap {
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
func (m CoordByteMap) RowAsString(y int) string {
|
||||
var res string
|
||||
for x := m.TLX; x <= m.BRX; x++ {
|
||||
@@ -403,6 +414,7 @@ func (m CoordByteMap) RowAsString(y int) string {
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func (m CoordByteMap) ColAsString(x int) string {
|
||||
var res string
|
||||
for y := m.TLY; y <= m.BRY; y++ {
|
||||
@@ -470,6 +482,7 @@ func (m *Coord3dByteMap) Get(pos Coordinate3d) byte {
|
||||
}
|
||||
return m.Field[pos]
|
||||
}
|
||||
|
||||
func (m *Coord3dByteMap) Opt(pos Coordinate3d, def byte) byte {
|
||||
if v, ok := m.Field[pos]; ok {
|
||||
return v
|
||||
|
||||
Reference in New Issue
Block a user