2025 Day 7 Complete!

This commit is contained in:
2025-12-07 08:57:46 -06:00
parent e724b08961
commit c16210ae92
7 changed files with 601 additions and 30 deletions

View File

@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"math"
"slices"
)
type CoordByteMap struct {
@@ -93,14 +94,14 @@ func (m *CoordByteMap) GetCol(x int) []byte {
func (m *CoordByteMap) AddRow(row []byte) {
y := m.BRY + 1
for x := 0; x < len(row); x++ {
for x := range row {
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++ {
for y := range col {
m.Put(Coordinate{X: x, Y: y + m.TLY}, col[y])
}
}
@@ -308,20 +309,29 @@ func (m *CoordByteMap) FindAll(b ...byte) []Coordinate {
return ret
}
func (m *CoordByteMap) FindAllOnRow(row int, b ...byte) []Coordinate {
var ret []Coordinate
if row < m.TLY || row > m.BRX {
return ret
}
for x := m.TLX; x <= m.BRX; x++ {
c := Coordinate{X: x, Y: row}
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 {
if !slices.Contains(b, v) {
ret[c] = v
}
}