Merge branch 'main' of ssh://git.bullercodeworks.com:2200/brian/adventofcode into main

This commit is contained in:
Brian Buller 2023-12-23 16:04:07 -06:00
commit 8df83e078d
9 changed files with 2042 additions and 1 deletions

131
2023/day21/input Normal file
View File

@ -0,0 +1,131 @@
...................................................................................................................................
...#...#.#.......................#.#......#........#.....#.#............##.................#..#....#.#.##.....#....................
...........#..#............#..............##...........................#.#........#...............#......#......#....#.####..##....
...#........................#...#....#......#.............................#.#..........#.#.......#..#...##.........##..#...#...##..
........#...#..........#........#..#...................#........................#........#...........#.........................#.#.
............#..#...#.#..#.........#....##.....#.......#.#...................#.#.............#.................#.....#.........#....
..#..#.#....###.....#........#.#......#..#.....#.....#......................#...#......##.......................#.........##...#.#.
.....................#...#.#....#.....#....#.....#..............#...........#.....##.#..#..............#.....#....##...............
.#...##...##..#.........#.#................#......#......................................##...........#..#.......##.#..#.#.........
.....#..#....#....#.#......#...#.............#..............#...#.#.....................#.......#.##.#..#...#...........#..........
..#...........#.#.........#..#....##.#.........#..##...........#...................##.##...#...#...................#......##.......
..#......#..#....#............#......#....#.......#.............#.#.....#........#.........#........#.......#.##.......#..#........
...#.......#....#...#..#..##...#.............................................................#.......#.......#.........##....#.....
.#.#..#..........##......#..#....#......##.........................#................#...........#.....#................#...#.....#.
.....#.#.............#.........#.#............#....................#.......#...................#............##..#.........#.#..#...
...#..#....#.......#..#...##...#........#...#.....................#.....#..............#..#.............#..........#.....##....#...
....#..................................#..............#................#.#...................#.#....#..........#.........#......#..
.....#...#....#...#.......#......#..#....................................#.#...................#.###.....###.......................
...##........#...............#..#....#....#..................#.......#......................##.....................#.#.#....##.....
....#...#......###..#....#..####..................##...#.#..#..##.#.....................#.................##.......#...............
.......#....................#.#..........................#..#.#.............................#................................##.#..
.#..#.......#..........#..................................#.#.............#.....#.#...............................##.....###....#..
....##.#...#.........#........##.......#............#.....##....#...#.#......#.............#..#..#.#...#..................#........
............................##.##.............#.#.#..........##........###..........................#..#....#.##...#...............
........#.#.....#...............#....#..................##.....##...........#...#...................#...........#......#...........
.#......................#.....#....#...................##...#..#..##..........................#..#...#..#...#...........#.#........
....................#.#..........#................#.................#...........#.#............#...#.........#.......#.............
...........#...............#.#...............##............#...#...........#........................#.#...##.....#.................
..............................#...........#.........#........#.#..#.#...#...#.......#.............#....#.....#.##....#......#..#...
.....#..................#...............#.......#........#...#....#.....##......#..#.....#.........#.#..#......#...#..#......#.....
..............#...#.....#..............##.........#.............#...##..#......###....##.#.........#........###...........#........
....#..................#.................#.....#......#.#.#.....#................#..#.....#.#...........#...................#......
..##..#.............................................#.#.........#...#.................#..#..#...........#..#.....#.........#.......
..............#.........#.............#.......#.....................##...#.....#..#...........#........#.........#.#..#.#..........
..#............#.........................#....#....#...........#..........#.#...........#..................#..........#.##.....#...
.....................##.................#.........................#............#...#.#........#....................................
.#.......#....##...#.#............##...#.#....................#.#.#.#............................#...............#.........#.......
........#.#......#......#...............#....................#.#.............................##..............................#.....
.#.................#...........##...#..#.#.........#........#.....#........#...............##...#.................#...#..........#.
..#.#.#...#.#...#..##...................#.......#....#...................................#.#........#............................#.
..#..............##............#..#.........#......#.........................##...#.....#.......................#..............#...
...#..........#.....#.....................###....#...........#.#.....#.......#....#..#...#.......................#.#....#......#...
....##..........#.##..........#.......................##.............................##..##....#............................#.#..#.
.......#..#..................#....#........#......#..........#......##...............#............................#..#.............
.#...#.#.#................##...#.....##.#....#...........#.....#................#......#.................#.........................
...................................#......#.#....#.......#.............#..................#..#.......#......................#....#.
..#........##........................#......#..##.#...#....#............#..........#.#.#.....##...#.#............................#.
......#................#......#.#.......#.#..#.#................#......##....#..#......................#.#............#....#.....#.
.........#..#................#.#....#...........#.......#..........................#..#....#.#..........##...................#.....
..#......#...........#.........#..........#...#..#..#...........#.......##................................................#.....#..
.....#..............#.......#..........#...#.......#.#...#..........#......#...#.#..##....#....#.#....#.#.......................#..
........#..............#.#........#.....................#....###...#.....................#.....#........................#.....###..
........#.........#.............#.......................#..#..............#..#........#................#...................#..#....
...#...............................#.....#..........#.....#.......##.....#........#...................#...#.#.....#........##......
....#..........##...........#........................#..##...........##.....#....#....#..#...........#.............................
..#................#...............................................#.....#...............##..#.#....#....#.....#...............#.#.
......................#.#..#.................#.....#.....#..##.....................................#......#..#..#..##..........#...
................#..........#..#..............#..................................#..........#......#....##........#....#..........#.
..................#...#.......#..................#..#..#.......#......#.....#.........#..##.....##.#...#...........................
................#..#.#.......#.##....#....#.....................#...##.#..#...........#...#....#..#.#.....#..#....#................
...............#..#...#.#....#.......................#.......#....#..........#...#.............#.......#.............#.............
.............#............#.........#.......#......#..##......##..............#.......#...#.#...#...........#...#.#.#..............
................................#.#.....#.#......#.......#............#...#....#........#......#.....#...#...#.............#.......
.......................##.#..#...#.....#....................#...#...#.....#.............#..........#.........##........#...........
.............#.#..#......#.......##........##..............##..#....#......#....###..#..#..........#...........#..........#........
.................................................................S.................................................................
......##.#...#...#.#........#........#...###........................#......##..##................##......#....#.....#........#.....
...............#................#....#.............#.##.....................#........#........#...##..###........#.......#.#.......
..........................#...........#....#.......#......##..##......#........##.........##.......#...#...........#.#....#........
.............#...........................#..#..##.......#...###.....................#...............#...#.................#........
...............#..##................#..###......#..#....#.#...........................#...#...#..........#..#......#...............
..........#..#.#......#.......##...#...........#.#.....###...#...........#...#..................##.......#........#..#.............
.#...................#.................#............#..#.##..................#............#...........#..#..#......................
..................#....#...#..#........#..............#...........#............##..##.......#..........#............#..............
...##...........#....#.....#...........................#................#.......#...#.......#.###.........#..#.#...................
....#.......................#................#....#....#.......#....#.........#..#.......#...#....#..........#..#..................
.##..#.............##......#.............#..##.................#..###..................#......#.................###................
...#.#.............##..##...........#...............#....#.........#....#...#..#..#.##.......#...#...#.....##.............#..##....
..................#...#........#.................#.............#.....##..#.#.........#.....................................#..#..#.
...................##........#..#........##......#....#...........................#.................#...........................##.
.##.....#..........#.....................#...#.......#........#........#.........#....#.....#...##.......................##.#......
...#.#.................#.........#.###...#..#..#........#....##.#...#........#.....................#...#................#..........
......#.#...#...........#......................##.#......................#.#................#.#..#.....#...........................
.....#..##...#........#.....#.#...#..#..#......#.....#........#.............#..................#.....................#.............
.##........#.................#.............#....#..#....#...#..........#..#............#............#......................#.##....
...........#.##.......................#......#.......#.........#.....#...#.............#..........................#..#....##....#..
...........................##.##.................##........##.............#........#.......#...#.#...................##.##.........
...#.....#........#.............##.#..........#.#.....................#........##.....#.....#..#...............................#...
.....#..#..........................#..........#...#...#..#.........#.........................#..#......#.................#....#....
.#..........#....#..#................#..........................#.......#..........#.#.............#............#..................
..................#................#...#.......#...#.......#.#.......#.#........#.........#...#.....#..........####..#.............
..#...............................#.......#........#.......#..#.....#..#............#...##.........#.............#..#.......###....
.....##..........#..................#............#.................#.#..........#.#.......##..#................#..##.........#..#..
....#...............#.............#.##...#...............#..#.....####....##......#..#..#........................##.......#........
.#.#....#..#..#.#..###.##..........##......#........#......................#....#........#.................#..........#............
....#.##.........#.....##.#.........#....................#...#..........#.......#....#.....#................#...........#.###...#..
.#................#..#...#............................#...##....#....##....#......#.....#......#.........#......#...............#..
..........#........##.......#.............##............#...................#..............#............#..#....#.........#.#......
..#........#.....#......##..................##.......#........#.........#.#..#.....#.#......................................#......
..#.......#.....#....#...#............#...#....#............#.........................................##.#..#.#..#.#...............
....#...#.........#.........#..........#.#............##.......#...#..#....#........#.#...............................#.#..#.......
..#.....#.###.#..#..#.#....#.................#......#..............................#...#...........................#.....#....#..#.
.......#.......#.#........#............................#............#.#..............................#.....#.#...........#.........
........#.....#..................................#....#...#.....#........##.........................##.........#.................#.
.........##..#.......................................#..#...#................#.................#............#..............#..#.#..
.#.........##.......................................##........#.................#................#..###......#......##.....#..#....
........#..........###..........##...#.......#..........#..#..............#.#................#.....#.#...#..#..#............#......
..........#.#...#.#....#..........#..............#.......##.#..................#..................................#....#...........
.........#....#.............#.#....####...........#......#......#..#.##........#.................#..........#................#.....
.#...#.....#...##.....##.##..#...#.#.#..........#.....#....#.#.....#..........#...#........................##......#.....#......#..
..................#.................................................................................#.#..#...#..#...#......#..##...
..#..........#.............#.......#.#.#..........#.......#.............................#.....#..............#.......#.....#.......
...##.##..........#.......................#........#....................#..............#....#...#............#..#..................
........#.........#...............#.#.....#...........#......#...........#.................#......#...#.#.....#......#......#......
....#...#....................#..........#.............#...#........#..#.#.............#...#...#...#...#...............#.......#..#.
.....#.#.#.##..#......#.....#..#........#.............#....#..#...........#.........................#.#..#..##...#..#......#...#.#.
..#........##...................##....#......................##............#.......#...#..#......#......##.............#...........
....#............#....#.............#.......#...........#.#..##...#...................#.........#.##.#.....#.......................
...#.............#......#....###......##....#...##.............##..#..............#................#.....##...#..##..............#.
.....#.......#........#..............#........#..#..................#...........................................#...#..............
..#....#............#.........#.....#.#...#.#......#................#..........##.#..#...................##...........#............
..............#.#....#...#..#.##....#...##....##.......................................#................................#......#...
....#........#..#..#............#.................................#.............................#..#.....#...#.............#.......
.#...................#......#......#..##...#...#..##..........#................#........................#......#......#............
.......#...#.##..##.#..........##..........#.....#................#..................#....#....#..................#...#...#........
......#..#..###.....##.#..#..#..#..........#................................#..........#..#......#.#............#.......#....#...#.
...#.....#..........#..#..#.#....#...#....#...#.....#.#..#......................#.....#.#......#...#.......................#..#....
..#.......................#.........#....#......#.......#...................#.#.#..........#....#....................#...#.#.#.....
........................#...#....#.##........................................#........#....#.#.......................#......##.....
.......#...#.......#....##.................#....#.#........................##........###.......#......#.........#..#...............
...................................................................................................................................

194
2023/day21/main.go Normal file
View File

@ -0,0 +1,194 @@
package main
import (
"fmt"
h "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func main() {
inp := h.StdinToStringSlice()
part1(inp)
fmt.Println()
part2(inp)
}
func part1(input []string) {
m := h.StringSliceToCoordByteMap(input)
start, _ := m.FindFirst('S')
m.Put(start, '.')
result := []h.Coordinate{start}
for i := 0; i < 64; i++ {
result = findNext(&m, result)
}
fmt.Println("# Part 1")
fmt.Println(len(result))
}
// 253370351984188 is too low
func part2(input []string) {
m := h.StringSliceToCoordByteMap(input)
start, _ := m.FindFirst('S')
m.Put(start, '.')
steps := 26501365
p := make([]int, 3)
size := len(input)
half := size / 2
fmt.Println("Getting Plots: p[0]")
p[0], _ = getPlots(&m, half, 5)
fmt.Println("Getting Plots: p[1]")
m = h.StringSliceToCoordByteMap(input)
p[1], _ = getPlots(&m, half+size, 5)
fmt.Println("Getting Plots: p[2]")
m = h.StringSliceToCoordByteMap(input)
p[2], _ = getPlots(&m, half+2*size, 5)
a := (p[2] + p[0] - 2*p[1]) / 2
b := p[1] - p[0] - a
c := p[0]
n := steps / size
result := a*n*n + b*n + c
fmt.Println("# Part 2")
fmt.Println(result)
}
var visited map[string]bool
func getPlots(m *h.CoordByteMap, steps int, factor int) (int, error) {
sx, sy := m.ColCount(), m.RowCount()
l := sy
expandMap(m, factor)
sx = l * (factor / 2)
sy = l * (factor / 2)
visited = make(map[string]bool)
return len(nextStep(sx, sy, 0, steps, m)), nil
}
func isPlot(m *h.CoordByteMap, x, y int) bool {
return m.Get(h.Coordinate{X: x, Y: y}) == '.'
}
func nextStep(x, y, step, max int, m *h.CoordByteMap) []h.Coordinate {
var acc []h.Coordinate
var key = fmt.Sprintf("%d;%d;%d", x, y, step)
if _, ok := visited[key]; ok {
return []h.Coordinate{}
} else {
visited[key] = true
}
if step == max {
return []h.Coordinate{{X: x, Y: y}}
}
if x > 0 && isPlot(m, x-1, y) {
acc = append(acc, nextStep(x-1, y, step+1, max, m)...)
}
if x < m.ColCount() && isPlot(m, x+1, y) {
acc = append(acc, nextStep(x, y-1, step+1, max, m)...)
}
if y > 0 && isPlot(m, x, y-1) {
acc = append(acc, nextStep(x, y-1, step+1, max, m)...)
}
if y < m.RowCount() && isPlot(m, x, y+1) {
acc = append(acc, nextStep(x, y+1, step+1, max, m)...)
}
return acc
}
func expandMap(m *h.CoordByteMap, factor int) {
stx, edx := m.TLX, m.BRX
for f := 1; f < factor; f++ {
for x := stx; x <= edx; x++ {
col := m.GetCol(x)
m.AddCol(col)
}
sty, edy := m.TLY, m.BRY
for y := sty; y <= edy; y++ {
row := m.GetRow(y)
m.AddRow(row)
}
}
}
func part2BruteForce(input []string) {
// Brute force just isn't going to cut it...
m := h.StringSliceToCoordByteMap(input)
m.StringEmptyIsSpace = true
m.StringEmptyByte = '.'
seen := make(map[h.Coordinate]bool)
start, _ := m.FindFirst('S')
m.Put(start, '.')
result := []h.Coordinate{start}
steps := 26501365
for i := 0; i < steps; i++ {
fmt.Println(h.CLEAR_SCREEN)
fmt.Printf("%d/%d (%f)\n", i, steps, float64(i)/float64(steps))
seen, result = findNextInfiniteRepeat(&m, seen, result)
if i == 100 {
break
}
}
fmt.Println("# Part 2")
fmt.Println(len(result))
for i := range result {
m.Put(result[i], 'O')
}
fmt.Println(m)
// It's making a diamond shape...
}
func findNext(m *h.CoordByteMap, curr []h.Coordinate) []h.Coordinate {
var result []h.Coordinate
for _, c := range curr {
for _, tst := range []h.Coordinate{
c.North(), c.East(), c.South(), c.West(),
} {
if m.ContainsCoord(tst) && m.Get(tst) == '.' {
var contains bool
for i := range result {
if result[i].Equals(tst) {
contains = true
break
}
}
if !contains {
result = append(result, tst)
}
}
}
}
return result
}
func findNextInfiniteRepeat(m *h.CoordByteMap, seen map[h.Coordinate]bool, curr []h.Coordinate) (map[h.Coordinate]bool, []h.Coordinate) {
var result []h.Coordinate
for _, c := range curr {
for _, tst := range []h.Coordinate{
c.North(), c.East(), c.South(), c.West(),
} {
if seen[tst] {
continue
}
wrkX, wrkY := tst.X, tst.Y
for wrkX < m.TLX {
wrkX += m.BRX
}
for wrkY < m.TLY {
wrkY += m.BRY
}
wrk := h.Coordinate{X: (wrkX % m.BRX), Y: (wrkY % m.BRY)}
if m.Get(wrk) == '.' {
var contains bool
for i := range result {
if result[i].Equals(tst) {
contains = true
break
}
}
if !contains {
result = append(result, tst)
seen[tst] = true
}
}
}
}
return seen, result
}

11
2023/day21/testinput Normal file
View File

@ -0,0 +1,11 @@
...........
.....###.#.
.###.##..#.
..#.#...#..
....#.#....
.##..S####.
.##..#...#.
.......##..
.##.#.####.
.##..##.##.
...........

1471
2023/day22/input Normal file

File diff suppressed because it is too large Load Diff

190
2023/day22/main.go Normal file
View File

@ -0,0 +1,190 @@
package main
import (
"fmt"
"sort"
"strings"
h "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func main() {
inp := h.StdinToStringSlice()
part1(inp)
fmt.Println()
part2(inp)
}
func part1(input []string) {
var bricks [][]int
for _, line := range input {
values := strings.Split(strings.ReplaceAll(line, "~", ","), ",")
var brick []int
for _, v := range values {
num := 0
fmt.Sscanf(v, "%d", &num)
brick = append(brick, num)
}
bricks = append(bricks, brick)
}
sort.Slice(bricks, func(i, j int) bool {
return bricks[i][2] < bricks[j][2]
})
for index, brick := range bricks {
maxZ := 1
for _, check := range bricks[:index] {
if overlaps(brick, check) {
maxZ = max(maxZ, check[5]+1)
}
}
brick[5] -= brick[2] - maxZ
brick[2] = maxZ
}
sort.Slice(bricks, func(i, j int) bool {
return bricks[i][2] < bricks[j][2]
})
kSupportsV := make(map[int]map[int]struct{})
vSupportsK := make(map[int]map[int]struct{})
for i := range bricks {
kSupportsV[i] = make(map[int]struct{})
vSupportsK[i] = make(map[int]struct{})
}
for j, upper := range bricks {
for i, lower := range bricks[:j] {
if overlaps(lower, upper) && upper[2] == lower[5]+1 {
kSupportsV[i][j] = struct{}{}
vSupportsK[j][i] = struct{}{}
}
}
}
total := 0
for i := range bricks {
satisfies := true
for j := range kSupportsV[i] {
if len(vSupportsK[j]) < 2 {
satisfies = false
break
}
}
if satisfies {
total++
}
}
fmt.Println("# Part 1")
fmt.Println(total)
}
func part2(input []string) {
var bricks [][]int
for _, line := range input {
values := strings.Split(strings.ReplaceAll(line, "~", ","), ",")
var brick []int
for _, v := range values {
num := 0
fmt.Sscanf(v, "%d", &num)
brick = append(brick, num)
}
bricks = append(bricks, brick)
}
sort.SliceStable(bricks, func(i, j int) bool {
return bricks[i][2] < bricks[j][2]
})
for index, brick := range bricks {
maxZ := 1
for _, check := range bricks[:index] {
if overlaps(brick, check) {
maxZ = max(maxZ, check[5]+1)
}
}
brick[5] -= brick[2] - maxZ
brick[2] = maxZ
}
sort.SliceStable(bricks, func(i, j int) bool {
return bricks[i][2] < bricks[j][2]
})
kSupportsV := make(map[int]map[int]struct{})
vSupportsK := make(map[int]map[int]struct{})
for i := range bricks {
kSupportsV[i] = make(map[int]struct{})
vSupportsK[i] = make(map[int]struct{})
}
for j, upper := range bricks {
for i, lower := range bricks[:j] {
if overlaps(lower, upper) && upper[2] == lower[5]+1 {
kSupportsV[i][j] = struct{}{}
vSupportsK[j][i] = struct{}{}
}
}
}
total := 0
for i := range bricks {
q := make([]int, 0)
for j := range kSupportsV[i] {
if len(vSupportsK[j]) == 1 {
q = append(q, j)
}
}
falling := make(map[int]struct{})
for _, j := range q {
falling[j] = struct{}{}
}
falling[i] = struct{}{}
for len(q) > 0 {
j := q[0]
q = q[1:]
for k := range kSupportsV[j] {
if _, ok := falling[k]; !ok {
if isSubset(vSupportsK[k], falling) {
q = append(q, k)
falling[k] = struct{}{}
}
}
}
}
total += len(falling) - 1
}
fmt.Println("# Part 2")
fmt.Println(total)
}
func isSubset(set1, set2 map[int]struct{}) bool {
for key := range set1 {
if _, ok := set2[key]; !ok {
return false
}
}
return true
}
func overlaps(a, b []int) bool {
return max(a[0], b[0]) <= min(a[3], b[3]) && max(a[1], b[1]) <= min(a[4], b[4])
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
func min(a, b int) int {
if a < b {
return a
}
return b
}

7
2023/day22/testinput Normal file
View File

@ -0,0 +1,7 @@
1,0,1~1,2,1
0,0,2~2,0,2
0,2,3~2,2,3
0,0,4~0,2,4
2,0,5~2,2,5
0,1,6~2,1,6
1,1,8~1,1,9

1
go.mod
View File

@ -9,6 +9,7 @@ require (
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7
github.com/go-gl/glfw v0.0.0-20191125211704-12ad95a8df72
github.com/nsf/termbox-go v0.0.0-20190817171036-93860e161317
golang.org/x/exp v0.0.0-20231219180239-dc181d75b848
)
require (

2
go.sum
View File

@ -17,6 +17,8 @@ github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+tw
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/nsf/termbox-go v0.0.0-20190817171036-93860e161317 h1:hhGN4SFXgXo61Q4Sjj/X9sBjyeSa2kdpaOzCO+8EVQw=
github.com/nsf/termbox-go v0.0.0-20190817171036-93860e161317/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
golang.org/x/exp v0.0.0-20231219180239-dc181d75b848 h1:+iq7lrkxmFNBM7xx+Rae2W6uyPfhPeDWD+n+JgppptE=
golang.org/x/exp v0.0.0-20231219180239-dc181d75b848/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191008105621-543471e840be h1:QAcqgptGM8IQBC9K/RC4o+O9YmqEm0diQn9QmZw/0mU=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

View File

@ -42,6 +42,39 @@ func StringSliceToCoordByteMap(input []string) CoordByteMap {
return ret
}
func (m *CoordByteMap) RowCount() int {
return m.BRY - m.TLY
}
func (m *CoordByteMap) ColCount() int {
return m.BRX - m.TLX
}
func (m *CoordByteMap) GetRow(y int) []byte {
var resp []byte
for x := m.TLX; x <= m.BRX; x++ {
resp = append(resp, m.Get(Coordinate{X: x, Y: y}))
}
return resp
}
func (m *CoordByteMap) GetCol(x int) []byte {
var resp []byte
for y := m.TLY; y <= m.BRY; y++ {
resp = append(resp, m.Get(Coordinate{X: x, Y: y}))
}
return resp
}
func (m *CoordByteMap) AddRow(row []byte) {
y := m.BRY + 1
for x := 0; x < len(row); x++ {
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++ {
m.Put(Coordinate{X: x, Y: y + m.TLY}, col[y])
}
}
func (m *CoordByteMap) GetPos(x, y int) byte {
return m.Get(Coordinate{X: x, Y: y})
}
@ -109,7 +142,8 @@ func (m *CoordByteMap) ToByteSlices() [][]byte {
return ret
}
// ContainsCoord returns true if the passed coordinate is in the map
// ContainsCoord returns true if the passed coordinate is within the bounds
// of the map
func (m *CoordByteMap) ContainsCoord(c Coordinate) bool {
return c.X >= m.TLX && c.X <= m.BRX &&
c.Y >= m.TLY && c.Y <= m.BRY