2023 Working on day 23

This commit is contained in:
2023-12-23 16:03:45 -06:00
parent 89bb8f2bb8
commit f5ce895221
4 changed files with 327 additions and 0 deletions

View File

@@ -86,6 +86,16 @@ func (m *CoordByteMap) Height() int {
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++ {
c := Coordinate{X: x, Y: y}
if m.Get(c) == o {
m.Put(c, n)
}
}
}
}
func (m *CoordByteMap) ToByteSlices() [][]byte {
var ret [][]byte
@@ -167,6 +177,20 @@ func (m *CoordByteMap) FindFirst(b byte) (Coordinate, error) {
return Coordinate{}, errors.New("Not Found")
}
// FindLast searches right to left, bottom to top for the last
// instance of b
func (m *CoordByteMap) FindLast(b byte) (Coordinate, error) {
for y := m.BRY; y >= m.TLY; y-- {
for x := m.BRX; x >= m.TLX; x-- {
c := Coordinate{X: x, Y: y}
if m.Get(c) == b {
return c, nil
}
}
}
return Coordinate{}, errors.New("Not Found")
}
func (m *CoordByteMap) FindAll(b ...byte) []Coordinate {
var ret []Coordinate
for y := m.TLY; y <= m.BRY; y++ {