Merge branch 'main' of ssh://git.bullercodeworks.com:2200/brian/adventofcode
This commit is contained in:
@@ -145,6 +145,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
|
||||
@@ -231,6 +241,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++ {
|
||||
|
Reference in New Issue
Block a user