2022 Day 14 Complete!
This commit is contained in:
@@ -3,6 +3,7 @@ package aoc
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
type CoordByteMap struct {
|
||||
@@ -14,11 +15,20 @@ type CoordByteMap struct {
|
||||
TLX, TLY int
|
||||
// The Bottom-Right-most X/Y
|
||||
BRX, BRY int
|
||||
|
||||
// Options for the 'String' method
|
||||
StringEmptyIsSpace bool
|
||||
StringEmptyByte byte
|
||||
}
|
||||
|
||||
func NewCoordByteMap() CoordByteMap {
|
||||
return CoordByteMap{
|
||||
Field: make(map[Coordinate]byte),
|
||||
Field: make(map[Coordinate]byte),
|
||||
TLX: math.MaxInt,
|
||||
TLY: math.MaxInt,
|
||||
BRX: math.MinInt,
|
||||
BRY: math.MinInt,
|
||||
StringEmptyByte: ' ',
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,6 +206,9 @@ func (m *CoordByteMap) Put(pos Coordinate, val byte) {
|
||||
m.Height = m.BRY - m.TLY + 1
|
||||
}
|
||||
}
|
||||
func (m *CoordByteMap) Delete(pos Coordinate) {
|
||||
delete(m.Field, pos)
|
||||
}
|
||||
|
||||
func (m *CoordByteMap) GrowNorth(size int, val byte) {
|
||||
tlY := m.TLY - 1
|
||||
@@ -249,7 +262,11 @@ func (m CoordByteMap) String() string {
|
||||
var ret string
|
||||
for y := m.TLY; y <= m.BRY; y++ {
|
||||
for x := m.TLX; x <= m.BRX; x++ {
|
||||
ret = ret + string(m.Field[Coordinate{X: x, Y: y}])
|
||||
if m.StringEmptyIsSpace {
|
||||
ret = ret + string(m.Opt(Coordinate{X: x, Y: y}, m.StringEmptyByte))
|
||||
} else {
|
||||
ret = ret + string(m.Field[Coordinate{X: x, Y: y}])
|
||||
}
|
||||
}
|
||||
ret = ret + "\n"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user