2021 Day 23 is complete, but not by code...
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package aoc
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type CoordByteMap struct {
|
||||
Field map[Coordinate]byte
|
||||
@@ -32,6 +35,56 @@ func StringSliceToCoordByteMap(input []string) CoordByteMap {
|
||||
return ret
|
||||
}
|
||||
|
||||
// FindFirst searches left to right, top to bottom for the first
|
||||
// instance of b.
|
||||
func (m *CoordByteMap) FindFirst(b byte) (Coordinate, error) {
|
||||
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) == 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++ {
|
||||
for x := m.TLX; x <= m.BRX; x++ {
|
||||
c := Coordinate{X: x, Y: y}
|
||||
for i := range b {
|
||||
if m.Get(c) == b[i] {
|
||||
ret = append(ret, c)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (m *CoordByteMap) FindAllNot(b ...byte) map[Coordinate]byte {
|
||||
ret := make(map[Coordinate]byte)
|
||||
for y := m.TLY; y <= m.BRY; y++ {
|
||||
for x := m.TLX; x <= m.BRX; x++ {
|
||||
c := Coordinate{X: x, Y: y}
|
||||
v := m.Get(c)
|
||||
var is bool
|
||||
for i := range b {
|
||||
if v == b[i] {
|
||||
is = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !is {
|
||||
ret[c] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (m *CoordByteMap) Count(b byte) int {
|
||||
var ret int
|
||||
for y := m.TLY; y <= m.BRY; y++ {
|
||||
|
Reference in New Issue
Block a user