2023 Day 11 Complete!
Added a todo file to track changes to my helpers that need to be propagated through previous days/years
This commit is contained in:
@@ -7,9 +7,7 @@ import (
|
||||
)
|
||||
|
||||
type CoordByteMap struct {
|
||||
Field map[Coordinate]byte
|
||||
Height int
|
||||
Width int
|
||||
Field map[Coordinate]byte
|
||||
|
||||
// The Top-Left-most X/Y
|
||||
TLX, TLY int
|
||||
@@ -34,8 +32,7 @@ func NewCoordByteMap() CoordByteMap {
|
||||
|
||||
func StringSliceToCoordByteMap(input []string) CoordByteMap {
|
||||
ret := CoordByteMap{
|
||||
Field: make(map[Coordinate]byte),
|
||||
Height: len(input),
|
||||
Field: make(map[Coordinate]byte),
|
||||
}
|
||||
for y := range input {
|
||||
for x := range input[y] {
|
||||
@@ -45,6 +42,13 @@ func StringSliceToCoordByteMap(input []string) CoordByteMap {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (m *CoordByteMap) Height() int {
|
||||
return m.BRY - m.TLY
|
||||
}
|
||||
func (m *CoordByteMap) Width() int {
|
||||
return m.BRX - m.TLX
|
||||
}
|
||||
|
||||
func (m *CoordByteMap) ToByteSlices() [][]byte {
|
||||
var ret [][]byte
|
||||
for y := m.TLY; y <= m.BRY; y++ {
|
||||
@@ -63,6 +67,54 @@ func (m *CoordByteMap) ContainsCoord(c Coordinate) bool {
|
||||
c.Y >= m.TLY && c.Y <= m.BRY
|
||||
}
|
||||
|
||||
// RowContains searches a row for a byte
|
||||
func (m *CoordByteMap) RowContains(row int, b byte) bool {
|
||||
for x := m.TLX; x <= m.BRX; x++ {
|
||||
if m.Get(Coordinate{X: x, Y: row}) == b {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ColContains searches a column for a byte
|
||||
func (m *CoordByteMap) ColContains(col int, b byte) bool {
|
||||
for y := m.TLY; y <= m.BRY; y++ {
|
||||
if m.Get(Coordinate{X: col, Y: y}) == b {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// InsertRowAfter grows the map south, moves all rows after 'row' south
|
||||
// Then fills the 'row'th row with 'fill'
|
||||
func (m *CoordByteMap) InsertRowAfter(row int, fill byte) {
|
||||
m.GrowSouth(1, fill)
|
||||
for y := m.BRY; y > row; y-- {
|
||||
for x := m.TLX; x <= m.BRX; x++ {
|
||||
m.Put(Coordinate{X: x, Y: y}, m.Get(Coordinate{X: x, Y: y - 1}))
|
||||
}
|
||||
}
|
||||
for x := m.TLX; x <= m.BRX; x++ {
|
||||
m.Put(Coordinate{X: x, Y: row}, fill)
|
||||
}
|
||||
}
|
||||
|
||||
// InsertColAfter grows the map East, moves all cols after 'col' east
|
||||
// Then fills the 'col'th column with 'fill'
|
||||
func (m *CoordByteMap) InsertColAfter(col int, fill byte) {
|
||||
m.GrowEast(1, fill)
|
||||
for x := m.BRX; x > col; x-- {
|
||||
for y := m.TLY; y <= m.BRY; y++ {
|
||||
m.Put(Coordinate{X: x, Y: y}, m.Get(Coordinate{X: x - 1, Y: y}))
|
||||
}
|
||||
}
|
||||
for y := m.TLY; y <= m.BRY; y++ {
|
||||
m.Put(Coordinate{X: col, Y: y}, fill)
|
||||
}
|
||||
}
|
||||
|
||||
// FindFirst searches left to right, top to bottom for the first
|
||||
// instance of b.
|
||||
func (m *CoordByteMap) FindFirst(b byte) (Coordinate, error) {
|
||||
@@ -199,12 +251,6 @@ func (m *CoordByteMap) Put(pos Coordinate, val byte) {
|
||||
m.BRY = pos.Y
|
||||
}
|
||||
m.Field[pos] = val
|
||||
if pos.X+1 > m.Width {
|
||||
m.Width = m.BRX - m.TLX + 1
|
||||
}
|
||||
if pos.Y+1 > m.Height {
|
||||
m.Height = m.BRY - m.TLY + 1
|
||||
}
|
||||
}
|
||||
func (m *CoordByteMap) Delete(pos Coordinate) {
|
||||
delete(m.Field, pos)
|
||||
|
@@ -23,6 +23,7 @@ const (
|
||||
|
||||
FILL_CHAR = "\u2588"
|
||||
CLEAR_SCREEN = "\033[H\033[2J"
|
||||
CLEAR_LINE = "\033[1K"
|
||||
|
||||
MAX_INT = int(^uint(0) >> 1)
|
||||
MIN_INT = -MAX_INT - 1
|
||||
|
Reference in New Issue
Block a user