2022 Days 12 & 13 Complete!

This commit is contained in:
Brian Buller 2022-12-13 10:08:27 -06:00
parent a4567a12c3
commit 6d22393da3
10 changed files with 1261 additions and 0 deletions

41
2022/day12/input Normal file
View File

@ -0,0 +1,41 @@
abcccaaaaaaccccccccaaaaaccccccaaaaaaccccccaaaaaaaacccaaaaaaaccaaaacccccccccccccccccccccccccaaaaaacccccccccccccccccccccccccccccaaaaaa
abcccaaaaaacccccccaaaaaaccccaaaaaaaacccccccaaaaaaaaaaaaaaaaccaaaaacccccccccccccccccccccccccaaaaaacccccccccccccccccccccccccccccaaaaaa
abccccaaaaacaaaccaaaaaaaacccaaaaaaaaacccccccaaaaaaaaaaaaaaaacaaaaaacccccccccaaacccccccccccaaaaaaaaccccccccccaaccccccccccccccccaaaaaa
abccccaaaaccaaaaaaaaaaaaacccaaaaaaaaaacccccaaaaaaaaaaaaaaaaaaacaaaacccccccccaaaacccccccccaaaaaaaaaacccccccccaaaccccccccccccccccccaaa
abcccccccccaaaaaacccaacccccccccaaacaaaccccccaacccccccaaaaaaaaacaacccccccccccaaaacccccccccaaaaaaaaaacccccccccaaaccacaaccccccccccccaaa
abcccccccccaaaaaacccaacccccccccaaacccccccccccccccccccaaaacaaaacccccccaacaaccaaaccccccccccaccaaaaacacccccccccaaaacaaaaccccccccccccaac
abccccccccccaaaaacccccccccccccccacccaaaacccccccccccccaaaacccccccccccccaaaacccccccccccaacccccaaaaccccccccjjjjaaaaaaaaaccccccccccccccc
abccccccccccaaaacccccccccccccccccccaaaaacccccccccccccaaaccccccccccccccaaaaacccccccccaaaaaacccaaccccccccjjjjjjkkaaaacccccccccaacccccc
abcccccaaccccccccccccccccccccccccccaaaaaacccccccccccccaacccccccccccccaaaaaaccccccccccaaaaaccccccccccccjjjjjjjkkkkaacccccaacaaacccccc
abccaaaacccccccccccccccccccccccccccaaaaaaccccccccccccccccccccccccccccaaaacaccccccccaaaaaaaccccaacccccjjjjoooookkkkkkkklllaaaaaaacccc
abccaaaaaacccccccccccccccccccccccccaaaaacccccccccccccccccccccccccccccccaaccccccccccaaaaaaaaccaaaaccccjjjoooooookkkkkkkllllaaaaaacccc
abcccaaaaacccccccccccccccccccccccccccaaaccccccccaaaacccccccccccccccccccccccccccccccaaaaaaaaccaaaaccccjjooooooooppkkppplllllaccaacccc
abccaaaaaccccccccccccaccccccccccccccccccccccccccaaaacccccccccccccccccccccccccccccccccaaacacccaaaacccijjooouuuuoppppppppplllccccccccc
abcccccaacccccccccccaaaaaaaaccccccccccccccccccccaaaaccccaaccccccccaaacccccccccccccaacaaccccccccccccciijoouuuuuuppppppppplllcccaccccc
abcccccccccccccccccccaaaaaaccccccccccccccccccccccaaccccaaaacccccccaaaaccccccccccaaaaaaccccccccccccciiiiootuuuuuupuuuvvpppllccccccccc
abcccccccccccccccccccaaaaaaccaaaaacccccccccccccccccccccaaaacccccccaaaaccccccccccaaaaaaccccccccccccciiinnotuuxxxuuuuvvvpppllccccccccc
abccccccccccccccacccaaaaaaaacaaaaaaacccccccccccccccccccaaaacccccccaaacccccaaaaccaaaaaccccaaccccccciiiinnnttxxxxuuyyyvvqqqllccccccccc
abcccccccccccaaaaccaaaaaaaaaaaaaaaaaaccaacccccccccccccccccccccccccccccccccaaaacccaaaaaccaaacccccciiinnnnnttxxxxxyyyyvvqqqllccccccccc
abaaaacccccccaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccaaaacccaaaaaacaaaccccciiinnnnttttxxxxxyyyyvvqqmmmccccccccc
abaaaaccccccccaaaaacccaaaaacaaaaaacaaaaaaccccccccccccccccaaccccccccccccccccaacccccccaaaaaaaaaaciiinnnnttttxxxxxyyyyvvqqqmmmccccccccc
SbaaaacccccccaaaaaccccaaaaaccaaaaaaaaaaaccccccccccccccccaaacaacccccccccccccccccccccccaaaaaaaaachhhnnntttxxxEzzzzyyvvvqqqmmmccccccccc
abaaaacccccccaacaacccccaaaaaaaacaaaaaaaaaccccccccccccccccaaaaaccccccccccccccccccccccccaaaaaaacchhhnnntttxxxxxyyyyyyvvvqqmmmdddcccccc
abaaaacccccccccccccccccccaaaaaacaaaaaaaaaacccccccccccccaaaaaaccccccccaaaccccccccccccccaaaaaaccchhhnnntttxxxxywyyyyyyvvvqqmmmdddccccc
abaacccccccccccccccccccaaaaaaacccccaaaaaaacccccccccccccaaaaaaaacccccaaaacccccccccccccaaaaaaacaahhhmmmttttxxwwyyyyyyyvvvqqmmmdddccccc
abcccccccccccccccccccccaaaaaaacaaccaaacccccccccccccccccaacaaaaacccccaaaacccccccccccccaaacaaaaaahhhmmmmtsssswwyywwwwvvvvqqqmmdddccccc
abcccccccccccccccaaaccccaaaaaaaaaacaaccaaccccccccccccccccaaacaccccccaaaacccccccccccccccccaaaaacahhhmmmmmsssswwywwwwwvvrrqqmmdddccccc
abcccccccccccccaaaaaaccccaaaaaaaaaccaaaacccccccccccccccccaacccccccccccccccccccccccaaaccccaaaaaaahhhhhmmmmssswwwwwrrrrrrrrmmmmddccccc
abcccccccccccccaaaaaaccccaaaaaaaaaaaaaaaaaccccccccccccccccccccccccccccccccccccccaaaaaacccccaaaaachhhhhmmmmsswwwwrrrrrrrrrkkmdddccccc
abccccccccccccccaaaaaccccccaaaaaaaaaaaaaaaccccccccccccccccccccccccccccccccccccccaaaaaaccccaaaaacccchhggmmmssswwrrrrrkkkkkkkkdddacccc
abccaaaacccccccaaaaacccccccccaaaaaacaaaaacccccccccccccccccccccccccccccccccccccccaaaaaaccccaacaaaccccggggmmsssssrrlkkkkkkkkkdddaccccc
abccaaaacccccccaaaaacccccccccaaaaaaccccaacccccccccccccccccccccccccccccccccccccccaaaaaccccccccaaccccccgggmllssssrllkkkkkkkeeeddaccccc
abccaaaacccccccaaacccccccccccaaaaaacccccccccccccccccccaacccccccccccccccccccccccaaaaaacccccccccccccccccggllllssslllkkeeeeeeeeeaaacccc
abcccaaccccccccaaacaaaccccccaaaaaaaaaaacccccccccccccaaaaaacccccccccccccccccccccaaacaaacccccaacccccccccggglllllllllfeeeeeeeeaaaaacccc
abccccccccccaaaaaaaaaaccccccccccccaccaaaccacccccccccaaaaaaccccaaccaacccaaccccccaaaaaaacccccaaccccccccccggglllllllfffeeecccaaaaaacccc
abccccccccccaaaaaaaaacccccccccccccccaaaaaaaccccccccccaaaaaccccaaaaaacccaaaaaaccaaaaaacccaaaaaaaacccccccggggllllfffffccccccaacccccccc
abcccccccccccaaaaaaacccccccccccccccccaaaaaaccaacccccaaaaaccccccaaaaacccaaaaaacaaaaaaacccaaaaaaaaccccccccgggffffffffccccccccccccccccc
abccccccccccccaaaaaaacccccccccccccaaaaaaaaacaaaaccccaaaaacaaaaaaaaaacaaaaaaacaaaaaaaaaccccaaaacccccccccccggffffffacccccccccccccccaaa
abccccccccccccaaaaaaacaaccccccccccaaaaaaaaacaaaacccccaaaaaaaaaaaaaaaaaaaaaaacaaaaaaaaaacccaaaaacccccccccccaffffaaaaccccccccccccccaaa
abccccccccccccaaacaaaaaacccccccccccaaaaaaaacaaaaaaaaaaaaaaaaaaaaaaaaacaaaaaaacccaaacaaaccaaaaaacccccccccccccccccaaaccccccccccccccaaa
abccccccccccccaaccaaaaaccccccccccccccaaaaaaaccccaaaaaaaaaaaaccccaacccccaaaaaacccaaaccccccaaccaacccccccccccccccccaaacccccccccccaaaaaa
abcccccccccccccccaaaaaaaaccccccccccccaacccacccccccaaaaaaaaaaccccaacccccaaccccccccaccccccccccccccccccccccccccccccccccccccccccccaaaaaa

87
2022/day12/main.go Normal file
View File

@ -0,0 +1,87 @@
package main
import (
"fmt"
"math"
h "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func main() {
inp := h.StdinToStringSlice()
part1(inp)
fmt.Println()
part2(inp)
}
func part1(inp []string) {
m := h.StringSliceToCoordByteMap(inp)
start, _ := m.FindFirst('S')
m.Put(start, 'a')
end, _ := m.FindFirst('E')
m.Put(end, 'z')
fmt.Println("# Part 1")
fmt.Println("Steps:", bfs(m, start, end))
}
func part2(inp []string) {
m := h.StringSliceToCoordByteMap(inp)
starts := m.FindAll('a')
if s, err := m.FindFirst('S'); err == nil {
m.Put(s, 'a')
starts = append(starts, s)
}
end, _ := m.FindFirst('E')
m.Put(end, 'z')
minSteps := math.MaxInt
for _, start := range starts {
curSteps := bfs(m, start, end)
if minSteps > curSteps {
minSteps = curSteps
}
}
fmt.Println("# Part 2")
fmt.Println("Steps:", minSteps)
}
func bfs(m h.CoordByteMap, start, end h.Coordinate) int {
seen := make(map[h.Coordinate]bool)
seen[start] = true
queue := []h.Coordinate{start}
steps := 0
found := false
// BFS Search
SEARCH:
for len(queue) > 0 {
k := len(queue)
for i := 0; i < k; i++ {
curr := queue[0]
currVal := m.Get(curr)
queue = queue[1:]
if end.Equals(curr) {
found = true
break SEARCH
}
for _, dir := range curr.GetOrthNeighbors() {
if !m.ContainsCoord(dir) || seen[dir] {
continue
}
newVal := m.Get(dir)
greater := m.Get(dir) > currVal
if greater && newVal-currVal > 1 {
continue
}
seen[dir] = true
queue = append(queue, dir)
}
}
steps++
}
if !found {
//fmt.Println("Path from", start, "to", end, "not found!")
return math.MaxInt
}
return steps
}

109
2022/day12/problem Normal file
View File

@ -0,0 +1,109 @@
Advent of Code
br0xen (AoC++) 26*
--- Day 12: Hill Climbing Algorithm ---
You try contacting the Elves using your handheld device, but the river you're following must be
too low to get a decent signal.
You ask the device for a heightmap of the surrounding area (your puzzle input). The heightmap
shows the local area from above broken into a grid; the elevation of each square of the grid is
given by a single lowercase letter, where a is the lowest elevation, b is the next-lowest, and
so on up to the highest elevation, z.
Also included on the heightmap are marks for your current position (S) and the location that
should get the best signal (E). Your current position (S) has elevation a, and the location that
should get the best signal (E) has elevation z.
You'd like to reach E, but to save energy, you should do it in as few steps as possible. During
each step, you can move exactly one square up, down, left, or right. To avoid needing to get out
your climbing gear, the elevation of the destination square can be at most one higher than the
elevation of your current square; that is, if your current elevation is m, you could step to
elevation n, but not to elevation o. (This also means that the elevation of the destination
square can be much lower than the elevation of your current square.)
For example:
Sabqponm
abcryxxl
accszExk
acctuvwj
abdefghi
Here, you start in the top-left corner; your goal is near the middle. You could start by moving
down or right, but eventually you'll need to head toward the e at the bottom. From there, you
can spiral around to the goal:
v..v<<<<
>v.vv<<^
.>vv>E^^
..v>>>^^
..>>>>>^
In the above diagram, the symbols indicate whether the path exits each square moving up (^),
down (v), left (<), or right (>). The location that should get the best signal is still E, and .
marks unvisited squares.
This path reaches the goal in 31 steps, the fewest possible.
What is the fewest steps required to move from your current position to the location that should
get the best signal?
Your puzzle answer was 449.
--- Part Two ---
As you walk up the hill, you suspect that the Elves will want to turn this into a hiking trail.
The beginning isn't very scenic, though; perhaps you can find a better starting point.
To maximize exercise while hiking, the trail should start as low as possible: elevation a. The
goal is still the square marked E. However, the trail should still be direct, taking the fewest
steps to reach its goal. So, you'll need to find the shortest path from any square at elevation
a to the square marked E.
Again consider the example from above:
Sabqponm
abcryxxl
accszExk
acctuvwj
abdefghi
Now, there are six choices for starting position (five marked a, plus the square marked S that
counts as being at elevation a). If you start at the bottom-left square, you can reach the goal
most quickly:
...v<<<<
...vv<<^
...v>E^^
.>v>>>^^
>^>>>>>^
This path reaches the goal in only 29 steps, the fewest possible.
What is the fewest steps required to move starting from any square with elevation a to the
location that should get the best signal?
Your puzzle answer was 443.
Both parts of this puzzle are complete! They provide two gold stars: **
References
Visible links
. https://adventofcode.com/
. https://adventofcode.com/2022/about
. https://adventofcode.com/2022/events
. https://adventofcode.com/2022/settings
. https://adventofcode.com/2022/auth/logout
. Advent of Code Supporter
https://adventofcode.com/2022/support
. https://adventofcode.com/2022
. https://adventofcode.com/2022
. https://adventofcode.com/2022/support
. https://adventofcode.com/2022/sponsors
. https://adventofcode.com/2022/leaderboard
. https://adventofcode.com/2022/stats
. https://adventofcode.com/2022/sponsors
. https://adventofcode.com/2022
. https://adventofcode.com/2022/day/12/input

5
2022/day12/testinput Normal file
View File

@ -0,0 +1,5 @@
Sabqponm
abcryxxl
accszExk
acctuvwj
abdefghi

449
2022/day13/input Normal file
View File

@ -0,0 +1,449 @@
[[[1,[1,6,0,10,10],[],5,[]],[3,[5,8],2,[3,6,5,7],8],4,[0,[10]],8],[7,7],[[3,[9,5,10],[3],8,10],2,3,9],[[8,[3,1,4,9,5]]],[[[],0],10,10,3]]
[[],[[[2,1,2,9],[]],[[1,5,10],3]]]
[[],[[1,[0,4,7,10,10],3,[6,2,0],[9,1,4]],[],[5,[0,8,5],0,10,[3,10,10]],2,2],[],[[[],10,[]],[3,3,[0,0,2,10],[7,8,6,4,6],6],[10,[8,2,4,2,0]]],[[[9,2,10],[5],1,5,[2,7,9]],[4,[6]],[[]],[4,[],[6,5]]]]
[[6,[]],[[[1],[6,4,1,4],3],[4,4]],[[6,[2,2,9],5,[8,9,7,10]],6],[5,[[10,9,0,5,5],[10,6,6]],[[10,9,6],[0,0,3,1],[],5],7]]
[[[4,[3,0,5,8,4],[5],7]],[[1,[3,9,10,3],6],7,2]]
[[[]],[],[[[5,7,8,8],[3,1,6,3],[6,7],4],10,8,[5,7,[5,0],9,7],6],[7,[4],7,[8,5],5]]
[[[],4,6],[0,3,2],[[5,[9,0,10,3,7]],[[5,6,7],[6,0]],9,[9]]]
[[[[7,8,9,3,5],6,[2,6],[6,1,4,10,8]],3],[10],[[]]]
[[2,8,[[8,3,1,5]],[[8,3],[1],[3],[],[5,8,8,9,4]]],[10],[],[6]]
[[0,[[6],8,4],6,4],[[[10,2],[6,4,4,9],8,[]],[0,5,4,[4,2,0]],1],[[[0,3,8]],8,0],[]]
[[5],[[],[[9,2,3,5,0],[1,2,7,5],5],0,[[4,8,10],[4,1],[9,1],3,10],3],[]]
[[],[2,[8],[],[2,8,7,[]],[[],[9,10,1,10],[],[]]],[6,[1,[],10,[3,1,5,1,7]],[6,[10,1],[0,10,4],4]],[]]
[[3,[[9,2,7],3,6,[6,9],[3,8,2,5,2]]],[],[[9,[5,8]],6,5,[[10]]]]
[[2,[1,2],[[6]],[6,8,6]],[[],[2,4,[7]],[0,2,[],[0,7,10,7,7],[10,2,8]],10,[[3],[7,4,8],[7,6]]]]
[[[[2,9],0,9,4],0,[[5,10],[0],5,[6,3]]]]
[[[9,1,[]],[[7,9,9,5]],[[3,6,0,1]]],[1,3,1],[0,1,[],[[3]]]]
[[6,6,[[5,8,6],[],[0,7],0]],[8]]
[[0,6,[[0,3]]],[9,[0,7,5,5],[[3,8,2,5],1],4,[10,[4,3],2]],[0],[[6],[1],[6,[],[4,8,6,10,0]]],[2,8,[6,[8],[8,4]]]]
[[7],[[],2,6],[3],[[5,[5,5,5,7],6],[6],1]]
[[1,[3,[8,4,1,0,1]],6,5],[1,[[7],[8,7,5]],8,[[],5],8],[],[[8,[]],5,4],[8]]
[[8]]
[[],[],[[[7,3],[9,0,0,2]]],[[9,0,[6,3,2,0,1],5],3],[[],[10,9]]]
[[[2,[10,10,9,6,7]],[5,1,3,7]],[[10],8,[[1,8,10,8,1],8,[1,2,4,7]]],[]]
[[10],[6,[],6,[[10,1],7,[5,1,0]]],[[0,6,[4,5],[9,0],6],[]]]
[[[],[],[]],[3]]
[[[[]],10],[[[0,9,8,9,4],[4,1,5,4],[7,6],3],10,2,0],[[0,6]],[9,3]]
[[],[[[9,4,8,1],0,8,[10,9]],[]],[[1,7,[5,9,3],8,5],3,[[8,9,10,2],7,[0,10,7],[8]],[5,[8,7,0,3,5],0],[9]]]
[[3,7,10,[[9,1,8],[4,5,0],8,[2,7]],10]]
[[[9,[5,10,3,5,1]],7,9]]
[[9]]
[[[[7,3,4,9,5],6,[4],4],[9,[9,9,3,4,6],5,8],[[1,6,8],[8,9,0,2],10]],[[],[4,[4,7]],3,[7,[],5,7]]]
[[[[0,7,7]],[[4,6,4],[7],4]],[0],[[],[[4,3,1,10,4],[2,0,9]],0],[[[7,1,5,8,9]],5,7,8]]
[[7,10,[5,[5,6,7],2,7],5,[[10,9],2]],[],[[8,[2,9,10],[10],[],[]],[]],[0,[9,0],[[],[4,2,10,6,5]],10]]
[[[[3,0,10,3]]],[[6],10,[1,3,[],0],4,7],[4,[],9,[[3,5,4,9,10],[0,8,3,4],[3,9,8,9],[1]],1]]
[[],[6,[7,5]],[6,6,3]]
[[],[[2,3],5,6],[7,[]]]
[[[],[1,[2]],4,10,[[],[],0,[3,6,10,4]]],[[1]]]
[[7,[5,3,9,[10]]]]
[[],[]]
[[[10],8,9,[4,10,[9,6],[1,0,6,7,8]]],[2,0,[1,2,2,2,6],[5,[3,0,9]]]]
[[4,0,4,2,[]],[0],[8,[8,[1,10],4,1],1,[5,6,2],2],[[5,2],0,3,[[8,4,6,9]]],[[[],9,[],9],[],[[2,5],[5,5,8,4],[4]],7,0]]
[[],[10,[4,5,[3,2,10,0,0],[5,3,6]],1,[2]],[[7,[8,7,3,2]],[5,10,10],[4,[10,7,0,6,10]],8]]
[[[[8]],3,[[2,1],1,4,8,[8]],8],[]]
[[10,9,[[6,3],[9,7,3],[6,8]],2,[[]]],[[[],9,[1,6,3,10]],3,[1,10],0],[[[0,8,5,2],1,2,[7,4]],5,[0,[8,7,1,1],5,2,[6,1,8]],1,[1,[8],[3]]],[[10,[0,7,8],10,8],7,[[]],0,[]],[5,8,1,[[],9,[],[0]],[]]]
[[[3,6,[7,10,0,2]]]]
[[9,[[4,6,10]],1,6,[5,[8,5],5,10,10]],[[],9,1,[2,[5,3],2,[6]]],[4],[],[[0]]]
[[[[7,3,5],[1]],2,[],4],[0],[9,[[4,2,5,9,6],2],[],[5,6]],[2]]
[[3,5,6,[[5],10]],[[2,[8,0,2,5,9],[]],5]]
[[[3],4],[[[2,1],[2,9,6]],[],0,4],[[[7],[7,3],0,8,9],[[10,9,10,6],[2,0,10,1]],9],[10]]
[[[]],[[],8,[[],[5,0],0,2,[3,7,8]]],[3,0,1,2],[],[10,10]]
[[[1,8,6,[9,5,6,6,3]],5,[[9,3,3,10],[8,0,1,9],9,[2]],8],[[[4,0,5],[4,10,7,4,0],9],4],[2],[3,[9,[],4],3,[[],0,7,6]],[]]
[[[0,[]],4],[[4,[5,7,10,5,1],5],[[10]]]]
[[[],[[10,8],[],[8,4]],1,0,[]],[[],[[2,0,8],4,9,7],[10,[0,8,4,9,5]],5]]
[[[10,5,[2,7,8],2],[2],7,[]],[6,2],[3,7,7,[[9,3,5,8,4],[3,0,4],[10,9,4,8,8],[2,4,7],7]],[[]],[1,5,[[10,3,4,1,5],6,[],10]]]
[[],[[[],[3,3,0],[4,0,5],[5]],[10,8,[2],[10,1,10,3],[10,7]],[[1,5,7,0],[8,5],10,8,[10,4,5,10]]],[7,[2,3,9,9]],[[8,[3,9,6]],[[8,8]],0]]
[[8,[9,8,[6]],[[8,7]],[4,6]],[],[],[[0,3,[7,9,6,9,1]],[[],[7,6,2,2,0]]],[[],[[0,2,2,3,7],8,[3,10]],1,[8,0,[6]],6]]
[[4,[1,9],0],[8,[2,[],[10,9,6,5],9,7],[[6,2,7,8],10,2,2,[0,10,2]],7]]
[[],[0],[2,[],[6,2,[4,4],[10,10,3,2,10]],10],[8,[],[8,8],9,10],[[[4,9],[8],0,10]]]
[[[[7],5,[4,2,5,6,6],[3,8,10,10,10],[10,10,9,7,9]],[6,9]],[2,[],[[2,2,9,2,10],[10,9],0,[5,7]]],[[7,2],7],[0,[7],[3,[]],6,3]]
[[5]]
[[[4,10],5]]
[[],[[[],[1,7,10,1,9],2,0,2],2,0],[[],[[8,2,5,4,9],7,8,3,[2,7]],5,0]]
[[10],[],[4,7,7,[[8],[1,8,8,6,10],[10,6,6],2],[4,[3,3,2,7,4],8,8,3]],[[9,[7,9,8,4],7],[[9,1,5,9,5]]]]
[[[7],6,[3,6,9]],[10,5]]
[[[2,[],9,6],4,4],[[[8,2,4],8,[8],[8,4,10]],[[7,6,4,10,9],6,6,3],10,[6,[10,2,3,8,7],4],6],[[],[],[3],[10],5]]
[[4],[[],[[10,9],[0,8,3,5]]],[[[],[2,2,1,10,6]],0,[[1,8]],6],[2,[[10],[6,3],7,[1,3,10]]]]
[[[],[[7,4,7,7]]],[7],[0,[]],[3]]
[[0,[[6,5],[2],0,[],[5]]],[[1]],[]]
[[[10,[7,7],[8,1,0,4,5],7],2,[[],[2,2,8,2],[5,0,9],5,[]],6,[[0,8,10],9,[5,5,6,8,0],[9]]]]
[[3,[[],[4,9,4],6,[5,2,8]]]]
[[[[3,2],2],6,[5,1,6,0],[],4],[[7],4,0,0,[[9,1],6,[8]]],[[6],1],[0,[[4,0]],2],[]]
[[[5,9,5,[],3],[2,6,[0,2,4,4]],0,0,[]],[[[],8]]]
[[[4,0,1,9],5,5]]
[[2,3],[]]
[[5,2,[[],[4,2,9,3]],[1,0,5],[7]],[[10,[3],[5],4],0,6,8,3],[9,[8,5],[4],3],[6,[],[8,9,5,[1,9,4,3,4],9],[2,10],8],[[[3,3,8,0]],8,4,[6,[1,5],[],[7,7]],5]]
[[],[8,5,[9,[5,5,7]],[[9,0,3,1],5,8]],[[]]]
[[],[[[6,2,9]],6],[[],[[]],8],[[[5,1],[0,8],10],[[],0,[4,8],[5],7]],[5,3,[9,[0],[],[3,10,3,6]],[7,3,0],[[1,10,8],7,[0]]]]
[[[],[3,6,4,[10,7,1],9],7,[],[0,[9,2,3],[9]]],[0,[4,4,4,9,2],[[8,5,8,3,10],8,7,5],1,[[6,0],6,0,4]]]
[]
[[],[1,5,8,10,8]]
[[8,7],[[9,4],10,5,2],[7,[[]],10,0,[10,4,[],[4,6,8],0]],[[[],[1,10,4,3],[1],10,[7,9,3,9]],[6,[9,8,7,0],6,[5,9,3,5,7],[8,3,4,1]],[10,7,9],9],[6,[[9,8],8,[2,6,4,9]]]]
[[[[1],[6,9,6,4,0]],[5,[4]],9]]
[[[[10,3,2,9,1],[1],7,2,2]]]
[[5,[[],9,[6,0,9,7,2],1],[]],[[1,2,[6,6],[1,7,1]],7],[[7,[2,5,3]],[0],2],[5,9]]
[[[7],[6],[3,2],[[3,5,2]],1],[[7],[[5,1,0,2],2,[5,7,2,4]],[[10],8]]]
[[[[],[8,2,7,4,4],[10,8]],[3,[3],[4]]],[[0,[10,5,10,4]],[[],[7,8,10,10,3],6],3],[[[10,4],7,[4,0],[7,8,0,10]],[1],[2,2,3,[5,6,8]]],[8,10,[[3,1,8,8],5,9,1,[10,6]],[[4,7],5,[1,9,10,0,4],2]]]
[[2,[4],9,[],[4,10]],[],[[[9],[0,0],[1,4,9,7],0],0,[[1,0,2],7,1],4,2]]
[[[6,10],[3,2,[1,1,7],[1],7]],[2],[1],[]]
[[],[4,[10],[[0,5,8,2,10],[],9,[0,3],[9,1]]],[9,1,8,[[1,10,8,3,4],[6,0,5,7,9],[2,10,3],3],6],[0,[10,[],2],5]]
[[[[10,3,9,2,5],2,[],3],10],[[[7,3,8,9,10],5,6,6,[1]],10,3,4,[[1],10,7]],[[[1,8,4,2,10],6,9,0,[]]],[[5,9]]]
[[[3,10,3,10]],[[6,7,[2,8,9,6,5]],6],[10],[6,[],[7,[8,9,4,2]]]]
[[[[9,7],[2]],[5],[]],[[[4,7,7],7,0],7,[[8,0],[],[4,5,6,2],[]]]]
[[]]
[[10,[]],[1],[],[[[8]]]]
[[[[5,0,4,10,0],5,[],[1]],[],[2],[[2,2,7,1,2],7,1,0,4],[10,[],5]],[[6,[5,9,6,3],3,9,[8,4,1,8]],[[3,3,8,3,0]],[6,[],0,[4,2],[]]]]
[[3],[[4,[8,4,10],7],[6,[5,9,9,2,4],[9,1,7,0],[5,9,5,0]],[4,10,[],[8,8,7]],1,10]]
[[[1,[8],[2,7,1],9],[],[9,1],[2,10,[8,10,7]],5]]
[[3,[]],[[],[9,9],0,8,[[8,8,1,5,6],[3,8,4,5,4]]],[[4,7,10,[7,2,0,0]],[[9]]]]
[[3],[4,7],[],[[1],[[4,9,10]],[[]],[],4],[[4,1],0,2,2,[2,[],[8,2,10],[9,0,10,4]]]]
[[5,9,[1,[0,9,10]],[1,9],7],[7,6,[[6,9],0],8],[1],[[6,7,3]],[]]
[[[8,4,[5,2]],0,[],8],[],[9],[[],[6,1,[3,0,7],1],[[9],7,[7],10]],[]]
[[2,[[1,2,8,8],[]],2,4,6],[[7]],[9,[10,[10,1,3,3,3],[3,10,10],5,7],7],[],[]]
[[10,1],[10,[[9],[9,1,5,9,5],[7,7,9,0],6]]]
[[[4,[10],1,[0,1]]],[[[7],9],6,9,6,6]]
[[6,[[],6,[7,8,8]]],[[1,3,[4,8,0,6],[1,10,3,9],10],[6,3],[9]],[],[[],[0,[10,3],[5],[7,5,10,5,2],[]],[4,8,3,[],[0]],[[5],[5,9]],[3,[5,2],[1,4,2]]]]
[[[[1,7],3,0,[]]],[1,6,[5,[10,8,8],[]],[[6,10,2,5,7],6,[7,7,9],[6,4,8,8]],1],[5,[[10,10],3],[[],[2,10]],[1,1,[6,5,7],[10,5,2]],0]]
[[7,[[7],9,[4,1,3,8],0,4],[1,4,[0,7,6,1,1]]],[0,[2,[3,9,7],10,5],[0,[9,4,2,5,3]]],[0,7],[[7,9,9,3,1],10,[],0]]
[[2,[]],[4,0,5,7]]
[[[8,7],[4,[7,2,2,8],[8,3,9,9],1,0]],[[[7,4,7,3,10],[1,4,1],[0,10],10,[0]]]]
[[],[],[7]]
[[1,[[5,7,2],[10],0,[8],[10,9,0,10,8]]]]
[[],[2]]
[[[10,[9,9,6,3],1,9]],[10,[4,[1,9]],[],[8]],[[3,7,[10,2]],[[],[1,3],2]]]
[[8,6],[[5,0,10,[9]],[[1,5,8,4]],[[1,8,4,6],[4,7,6,2,0],[6,0],[6,3],[6,9,9,10]]]]
[[10],[8,3,2],[2,[1],[],6,[[6,8],[6,7,5],[9,2,9],7,7]]]
[[[3,[],[10,3,9],4,[5,9,10,3,8]],[2],0,[3],[[3,0],3]],[[7]],[4,[],[],[[9,3,5]],[[]]],[[10],[[6],7],[[1,4],1,[1,1,3],[5,0,4,5,6]],[[4],[7,0,4]],3],[[[],3,[]],8,[9],4]]
[[[7,[1],[8,4,3,7],3]],[[],[[5,5,3,8,7],[7,5,10,1,1]],8,8],[[2,[7,7,9],10],[4,[4,0,4,2],10,[1,10,9,6]],[[0],0,7],[0,8,[5,0,10,2,3],[7,3,6,5,5]]]]
[[9,[[8,5]],3,7,5],[[1,[],0,1]],[[[10,8],10,[1],[9,9,3,4]]],[8,[[5],2,3,[],[4,0,5]],0,5],[[4,[5,5,0,10],6,10],2,7,[],9]]
[[[[]],6,[[5,1],8,[4,10],4,[10,5,0,6,5]],1],[[4,[4],6],5,7,[[2],[10,1,4,5,4],2,6,[8]],4],[[],7,[[10],[1,5,9,3,9]]],[[1,[],2],[],0,7,[[7],[7]]],[[],[[9,0]],[0]]]
[[1,9,[],6],[[[9,0,4,3],[8,1,4]],0,[]],[1,[3,[2,4],[]],6,1,3]]
[[4,8,[1,[7,9,5,8,3]]],[[[6,5],[6,1,5,6,0],7,3],[]]]
[[7,0,7,[],[1,[7,1],10,[7,5,8,6]]],[],[[],4,[1,8],[[7],[5,8,0,4],1,[],9],[[],9,1,7]],[[[7],3,[10,2,2],9]]]
[[7,[[9,7,9,4,3],6,7],9],[1,0,[[1,2,0,7],[9],8,[10],[5,7]],[7]]]
[[[6,4,9],0,[],6]]
[[1,[[2,0,2,2],8,5],[],[[4,3],[10],[6],10]],[6,[7,1,[0,2,6,1],9,[0,5]],[[1,5,10,10],[7,8,3,10,3],[],2],7,[9,8,9]],[5,6,[[10,3,2,6,3]]]]
[[5],[[[4],[6,0,4,8]]],[[3,2],[10,[4],[1,8],8],5,1],[]]
[[10,[[],[4,3,6,2,10]],9],[[2,[5],2,[8,8],[8]],1,[5,4,10,0,[6,2,5]]],[[[3,7,9],[7,5,2,4]]],[10,[7],[3],8,8],[]]
[[4,5]]
[[1,[[6,5,2,7,0],4],[2,1],9],[],[[[4,3,1,0,1],9,1,6]],[[[6,7,0],1,5],5,7],[4,3]]
[[[1,[3],0],[[5],[10],2,[2,1,3,6]],6,[1,[7],1,[],7]],[[],[[10,4,7,7,5],4,[4,5],[3,6,10,9]],[[2,8,5,7],[8,1,0,9]],[[0,6,8],0,7,5,[4,1]],[3]]]
[[],[9,4,5,[]],[[],5]]
[[[9,0],10],[],[[10,10,[8,2,7],[4,7,3,10,2]],2,1],[[],7],[9,1,[],[[4,7,2],[4,0],0,2,7]]]
[[[10,[1],[0,3,5,7,9],1,[1,9,5,9]],[2,[10,4,6]],1],[2]]
[[[7,[9,6,6,7],1],6,10],[5,[7,[9,9,9],8]],[7],[9,8,[[0,5,1],[0,3,2,9]],6],[3,3]]
[[[[4,2]],[[9,10,9]]],[2,[8,[],7,[10],[]],3,2,6],[[0,8,[6,1,6]],1]]
[[[1,[5,9]],9,5],[[[],6,7,[],1],4,[[5,3],[10,2,7,3,10],[6,1,1],4,[]],2],[],[[7,[0,3,5]],[0]]]
[[3],[4],[[4,[10],7,[2],9],[1,[5,2,10,3],[9,6,1]]]]
[[],[[[6,9,7,10,8],4,6],[[5,5,9,8,3]],8,10],[6,9],[9]]
[[6,8,[10,9,8]]]
[[[0,3,[],[4,9,5,5],3]],[],[],[9],[[4,[5,3],[3,5,8]],6,[7,9]]]
[[3,[[]],[[3,4,2,10,0],10],[3],[[],9]],[1,2,4,9]]
[[[9,[0],8],0,3,10],[[4]],[9,7],[1],[[[0,3,0,0,7],1,[0,7],[4,3]]]]
[[[[8,6],2,6,4,[8,8]],[[]],[[],4,1],[10,[8,4,1,6,6],[4,9,7,6],9]],[6,10,8],[1,9,[]]]
[[10],[5,4,10,[[],3,4,5]],[[],3],[2,[4,[7,2]],6,10]]
[[6,9,10,[7]],[[3]]]
[[[[7,7,1]],0,1]]
[[[1,6,8],7,[[4,6],[8,9,5],[7,7,9],10],1,[7,[7,0,5],5,0,[3,7]]]]
[[[[8,1,7],[8,1],0,[0,6,8],[5]]],[5,[4,10],[1,[5,2,8,4,0]],[[7,10,6],3]],[],[8,[5,[5,4],[3]]]]
[[9],[[],[[5,4,6]],0],[6,6,6],[[[6],[4,6,5,5],1,0,[5,5,3]],4,4,[[6,8,7,5],[10,8,1,8,6]],[6,[10,0,2,8,9],[10,4],2,[10,5]]],[9,[],1,9]]
[[10,[3,[3,0,8],[10],[5,5,8,1]],[[3,0,5],[8],8,7]],[8],[[[],[7,6]],4],[10],[6,[]]]
[[[[5,0,2,9],5,[8,8,0]],[8,10,[8,9,4],[8,3,10,9],[6]],5],[[0,10,[10,8,3],8,6],6,[[9,9]],[3,[3,7,10],[8,2]],[[],9,3,[9,0,8]]],[[0],4,[7,9],[[2,10,5,7,5],[8,0,1,5],[6]]]]
[[],[10,[[7],8],4],[0],[[10,5,[0,9,9,4]],[]],[5]]
[[[0],3,7,7,[1,[0,4,8,9,7]]],[[3]],[7,[7],2,[3,[7,7,0],[6,10,4,7,9],[8,10,2,8,2],[9]]]]
[[5],[9,[6,[]]],[[5,2,[],9]],[[]]]
[[],[[[0,0,6,9],[6,3,2],5],[5,[2]],7],[[[5,2,4],[2,8],[4]],[5,[]]],[],[]]
[[[5,1,[6]],[[3,7],6,[6,6,8,3],[],10]],[],[[],1,[9,[7,2,10,2,9],7]],[6,[1,[0,10,10,1],2,7,[]],[[],1,5],[[7,3,1],[2,8,10,9],[9,5],4]],[[],9]]
[[[3,6,10],[[10,4,4],[9,0],10,[]],[9,[],[5,4,3,6,6]],6],[],[],[4,3,4,10],[[[10]],0]]
[[[[3,0],[6,2,8]],[[3],5,[],[10,8,7,6]],[9,6]],[]]
[[[],[6,7,6]],[1,[[],[8,1],[],[6]],9,[[5,0]],[2,9,8,5]],[5,[[10,4,4]],10,8]]
[[[[7,10,8],[8,6],6],2,[7,[2,8],1]],[[7,3,9,9,[6,4,8]]],[[4,1,[0]],4,7,[[10,2]]]]
[[[9,[10]],5,[[0,9,3,0,6],6,1,[0,10,2],4],4],[4,[[1,5,8,5]],3,6,[6,[8],[6,1,3],[2,2,0]]],[]]
[[],[4,1,[8,2,6],7]]
[[[9,[5,0,2,9],[5,9,3,7]],4]]
[[],[[3],2,3]]
[[5,5]]
[[],[7,0,10],[[]],[]]
[[],[],[[8,9,8,3,[4,5,2]],[[3,3,1],[],[6,9,1]],[4,9,[8,10,10,1],7],0,1],[]]
[[[9,6,5,10,1],8,9,[[7,10,3,9,5],10],2],[4,[],8]]
[[[[6,0,7,9,5]]],[[[4,4,3]],7],[[[7,0,2,9],[]],[5,[],9],4,[[8,8,9],[],2,[8,4,2,9,0],[4]],1],[8,6,6,[]],[[1,0],[],3,[6,[1,9],[6],[5,6]]]]
[[],[[[10,10],[]]],[]]
[[[2,[6,4,8],10,[6,6,3,9],4],[0,9,1,[]],[[],[3],9,5]],[[[6,7,8],[4,0],[9,5],[0],[3,10,3]],9],[],[],[[[4]],3,[[1,4,2,8],[5],5,[5,7,7,6],3]]]
[[10,7],[]]
[[7,2,2],[],[[],1,5,[5,9,[1],1,4]]]
[[4,5,[[9,10,0],6,7],3,6]]
[[],[5,[[4,10,4,5,2],[3,7,7,1,5],[7,4,1,5]],[[3,3],10,1,10]],[[],[[4,10]],9,10,10]]
[[],[5,[[1,4],[5,4,6,5,0],[10,10],0,[3]],[6,3,3,[0,3,5,0]],[[3,8,10,2],[4,4,2,2],4,[6],8]],[[[6,2],9],7,3],[10],[[],0,1]]
[[3,10,[],6],[[[]],6],[]]
[[[],6],[[],0],[[8],[[5,5],[],[8,4,7,6],[7]],[],1,[9,5]]]
[[],[7],[6,[3,2],0],[[[7,1,7],[6,5,1,8,8],[9,3,6,4,2]],[2,4]]]
[[9,[[7],0,[]],[9,[10]]],[10,0,[9,[1,1,5],[6,7]]],[1,9,2,[[5,3,1],9,0,5]]]
[[4]]
[[[[7,6],[10,7,5,2,0]],8,2,7],[3,[0],[7,0,[2,9],4]],[[3,8,2,4,[]],[[],[8,4,7],[2,9,8]],[[9,2]]],[5,[10],[[],[4,2,3],3,[1,7,5],[1]]]]
[[[[4,2,6],6,[9,6]]],[9,7,[[4,9,5],[10,1,8,7],6,3,1],[2,[4,6],1,8],1]]
[[[[8,1,1,6,7],[7,6,5],[6,8],[],[1,5,0,2]]]]
[[[[1,2,5,7],[],[7,2,3],10,8],4,10,4,10],[3,[6,[6,1],[3,7,0,7,0],10],[7],7]]
[[1],[[[1,9,4,8],[0],[10,5,8],[10,8]]],[3,7,5,[[1,2,9,1,7],[7,10,5,8,6],[0,3]],3]]
[[10,0]]
[[],[0,[1,[]],4],[8]]
[[],[[[10,3,2]],2,[[10,5,2,1]],[2,[]],[[1,9,4]]]]
[[[[4,9,2]],1,0,9,5],[[[0,5,10,1],[6,7],4,[1,6,4],[3,7]],[[0,10],2,5,9]]]
[[2,[10],7],[10,[[3,2],[7]],[7,[6,9,9,4],3,[7,1,2]]]]
[[[[9,6,4],8,[6,0,6,10],[7,1,0]]],[],[8,[9,[6,0,4,8],8,3],[],[1,[4,7,2,4]],0],[[[6,1,5],5],5,1],[4]]
[[[],[[],[]],[8,[5,2,7,7,8],[1,6,4,3,1],[0,10]]],[[[6,7,4]],3,[[],[6],[2,7,4,9]]]]
[[[[7,4,7]]]]
[[[[3,9,1,3,8],10,[2,6,8,2]],[],1],[1,2],[8,2],[]]
[[0,[6],[[6,9,8],5,4]],[[0],[],6,[6,[6,3,2]],3],[7,[[]]]]
[[9,10],[1,6],[]]
[[3],[6,1],[[[3,8]],2,[[],[3,9,8,0,2]],[]],[[1,3],4,[6]],[6]]
[[2,[3,5,1,5,[1,8,2]]],[5,5,[[8,4,8],10,[10,4],6]],[[[10,9],[3,9,8,2,8],[]],8]]
[[[5],6,[2],9],[10]]
[[2,[0,[6],6,3,[8,4,10]],[[9],7,[3,10,1],[10,5],9],4]]
[[[[9,10,5,6]]],[[2,9],[10,8]]]
[[3,[[6,1,0,2],[9],2,3],[5,[6,3,0,10],1]],[]]
[[10,9,[],[]],[[6]],[0],[10,[10,6,5,[1]],[[3,10,0,8,1]]]]
[[7,[[4],2,5],2],[[1,3,[7,4,4,9,5]]],[3,2,[[],1,2,[4],[6,4]],[]]]
[[],[[[]],3,[7,2,[]]]]
[[1,[[6,9]],5,[[9,5,5,5],9,8,8],[3,2,5,[4,0,4],3]],[4,7],[[[4,2,7,3],[5,1],[10,4]],[[2,9,2],[7,8,1],[10,4,2,3,6],[],5],[10,9,[]]],[9]]
[[[5,10,[6,5,9,3,3],8]],[],[[7,[4],1,0,[9,4,8]],[[10,1],2,3,6],8,3]]
[[8,4,3,8,[1,0]],[5,[7,[],7]],[10,[[6,2,4],[7,3,7,5],[],[],1],6,2],[[],[[0,9,6],[],8]],[9,[],10]]
[[[[10,8,5,0]],[]],[7],[[1,[2],[8,0,0]],[[2],[],[2,1,1,0,8]],3,[[10,4]],7],[10,[1,[4,5,7],10,5,[8,5,2,10]],1,9]]
[[1],[0,1,[2,7],[[10],1,[]],[[3,3,4,2,5],4,[],[6,3,1,10],3]],[[3,[9,9,9,1],[8,9,0],0],3,3],[10],[[9,[9,1,6,7],7]]]
[[1,4,[],5],[4,[2,8,6,[3,5,6,4]],3,4,[[],2,[]]],[[[7,1,0,1],[6,10,9,8,3]],[[10,10],6,[]],0],[]]
[[2,10]]
[[[0],0,[[1,0],[5,5,9]]]]
[[5,[[3],10,[9,9],[6,4],[]],[5,3,9,[5,0,10,4],9]],[[[0,1,1,8,5]]],[[],[[2,9,7,2],3,1,[6,3]],8,[]],[],[9,9,[[4,0,4],[],3,1]]]
[[],[8,9],[[],9,3,5],[[9,1,[1,4]],[[2],[6,8],[4]],[[],4,[]],8,4]]
[[0],[4]]
[[[4,7,1,6]],[[10,3,3,3]]]
[[[[2,9,9,7],1],[1,3,[1,9,8,9,8],10],3,3,5]]
[[[1,6,[3,7,3,0,4],10,[5,2,7]],[[6,5,10,8,6],[8,3,10,5,10],[9,3,5],2,4],10,[7,6]],[1],[[[4,9,3],6,2,[5,4,4,1],2],[[0,3]],9]]
[[8,[],2]]
[[3,[5,2,[5,1],[8,4,4],10],6,[[1,4],[]],8],[6,10],[[1,4,[5],2,0],4,[[],3],[5,6],2]]
[[1,9],[]]
[[2,[0,3,8,2]]]
[[[6,5,7],[2,6]],[10,7,[6,9,6,[3,8,2],[]],1,10],[[[5,2,6,5],4,[]],[6,0,6],1,[]],[5],[[6,3,[7,7,3,2,0]],[[],[7,1,3,5]],[]]]
[[4,[[3,6,9,8,4],0,8,[10,0]],6,0],[3,1,[[7]],[6,8,8,1,4],2],[8,[6,[1],4,0,[8,3,8]],[3]],[[[7,5,3,10]],6,2],[2,[0,[]],5,[4,7]]]
[[5,0,1,[9,[],[1,10,6,6],[]]],[],[[1],8],[[2,[1,9,1,3]]],[[[],[],7,9,[]]]]
[[],[],[4,2,[[],[3],[3,2,8],0],[[10],[0,7,5,0],[10,8],0,[]],[[],6,2]],[[[5,8,1],[2]],[8],6,[1]]]
[6,0,1,5,5]
[6,0,1,5]
[[[4],[],4],[2,[[],[0,5],7,[4,4]],[[9,6],5]],[],[[],2,[],7]]
[[[7,[9,8,8,3]],[],[],6],[9,[[2,0],[7,0],2],5,[[]],[[3,3,6],6,[1,6,1],[10,4]]],[8,[9],4],[[[],[10,0,5],8]]]
[[[[9,10,2],3,5,[9,8,8,9],4]],[6,[]],[[],[4,10,2,6,[2]],6],[4,6,5,[[],[],3,9,[4,0,2]],5]]
[[5,[[],[1,4,2,4],1]],[2],[7,[8,4,4]]]
[1,9,4,8]
[1,9,4,8,5]
[[[[],8,[7,9],4],10,[4,[10,8,4,0]],[3,[10,7],1,[]],[[8,6,8,7,8],2,9]],[]]
[[6,0],[10,10,6,[2,[],[8,1,6,4]]]]
[[8,6],[[[]]]]
[[5,6]]
[[],[],[[7],[8],[0,8,0,5],9,2],[1,3,3,[7,8],[4,0,[6,3,9,1],[3,8,4,2,5],[9,5]]],[10,[[0,9,0],[7,9]],9,3]]
[[],[[7,7,[2]],[[6,5,10,7],[8,4,9,0,4],6],[2,9,[4,8],10,5],[2,[7,10,0,1],[3,7]]],[[[5,4,0],[6,5],7,0,[2,6,5]],4,1,[4,10,1,2]],[[3]]]
[[9,[],3],[10,[4,9,10,0]],[[],5,[[8,0,7,9],6,3],[[10,4],[8,6,0,7],3,2]],[2],[[5]]]
[[[[4],9,[0,7,4,10]],8,[5,8,6,0]],[6],[5,[[],[7,0,5,5],0,[]]],[1,[1,[7,1,10,0,8],2],[2,[9,2,2,8],1,10,[6,9,3]]]]
[[[],4,[10],[5,[1,0,9],2]],[[6,[4],2,4,10],6,[5],[2,7,[7,6,3,4]]],[[7,1,[5]],10,[1,[0],[],[8,9,9,7],7]],[6,[8],1,3,10],[10,[9]]]
[[1,1,0,0],[1,[[3,10,6,9,10]],[[3,0,6,4,9],0,2]]]
[[10,[7],5,[],6],[[7,[3,10,9,1],[8],[],[1,0]],[5,8]],[7,[[4,4,0]],10,[3,[9,3,5,2,0],9]]]
[[5,[[4,8]],9,[0,[7,7,8,0,3],4,10],[10,[5,1,7,7,10]]],[],[6,5],[[],7,1,[[],[0,8,1],10],[]],[[],[],[3,10,[2,9,10,4,10],4],10,[10,[10,10,6,8,5],[5],6]]]
[[[],2,[10,[6,3,10,7],[]],[]],[],[[4,7,[],7,[]],[[1],10,[8,0],10,2],[[8,0,3,3,4],[7,2,3],[3,8,6,9],9],[],[6,8,0,[7]]],[10],[[[8,0,4,6],3,[]],0,6,[[6],5,7,9],[[4,0,7,5]]]]
[[1,[[0],[],[],5],8,6],[0,[2,6,2,[9],6],2],[[[0,4,5,5,4]],[4,5,1,6],3]]
[[[[5,4,0,9,10],[0,0,7,8,5],[4,6,7],8,5],[[5,2,0,7,3],5,[],[0,0]],[1,3,1,[2],[]],8]]
[[[1,[9,4,4],[8,1,5]],[[5,2],4,10,3,10]],[[[9,6,8]]],[[4,[6,0,2,9,8],[],[10,10,9,2,2],0]],[10,0,[]]]
[[],[[7,[10,9,10],4],[2,2,[1,0]]],[[2,[3,8,5,9,3]],[[3,2,9],[],5,8],[],[[10,2],0,[]],[[10,6,0],5]],[3,[],[],[2,5,[4,8,1,7],4],[]],[8,1,[[3,4,6,7,1],7]]]
[[1],[[[4,7,9,10],3,[5,9,7,9,10]]]]
[[1,10,[7,[],[7,6,3],10,9],[[0,10,0]],[4,6,[3]]],[[[6,2,6,3],10,[3,0,7,4]],5,10,6,[[5],6,[],9,[8,2,10,0]]],[],[[[0,8],10],8,[[1,8,1,3,6],2,[6],[7,0]],1]]
[[[3],3,[8,7,[10,8,4,3,6],2],[6,2],5]]
[[[[1,0,4,3],[9],[1],2]],[[8,9,0],[],10,8,[[5,5,6,5],6]],[[[9],0,10],1,[2,8]],[9]]
[[[2],7,0,1,5],[[[1,6,4,3,4],6,1],[],5,[],[[7,4],[4,1,8,7,0],[],6]],[0,[0,[9],[9]],[10,1,7,[]],2,[[6,5,9,1],[3],5,[5],4]],[8,10,[[10,5,4],0],[5,[10],10,[1]]],[]]
[[],[2],[1],[9,[[1,2,7]]],[[[1,1],[2],10,[7,1,0]],6]]
[[4,[[9,8]],[[9,3],1,[6]]],[[[4,2,5],[],[],2,6],3],[[[1,0,5,6],[2,6,10,5,9],[1,4,3,0,2],[10,2,9]],[5,2,7,[10,10,9,4,3]],[[3,5,8,9],[10,1,3,10],[],[2,8,1,8]],3,[]],[0,[],[[2,4],[8],[],[5,7,1,1]]],[[[],9,1,7],7]]
[[4,0,[1,10,[],0,[]],8,0],[],[],[4]]
[[4,[9],2],[9],[3]]
[[[[6,0,4,2,0],9,[7,8],8]],[],[[2,7],1,4]]
[[],[[]],[],[[[9,7],4,[0],[3,10,10,8,4]],6,5]]
[[[7]],[],[],[[],[7]],[7,[3,6,3],1]]
[[[8],[7],[3],[[3,2,4,9]],4],[[5,0,[3],[6]]],[[[9,9],[10,1,0,6,3],2]],[0,[2,8,[4,4],2],2]]
[[],[[[4,3,0,2],[2,4,10,5,3],[]],[[5,9],7,[4,6]],[[6,6],[6,9,2,4],[9,8,9],8]],[[],2,8,8]]
[[[5,9,10],[4,[10]],[[],[9],[]],[4,2,6],2],[[4,[7,3,1,9,3],[3,1,6,5],8]]]
[[[[4,0],10,3],[[6],[],10],10,6],[8,7]]
[[],[],[10,2,0],[[[3,8,7],[2,0]]],[3,5,5,1]]
[[[[8,7],4,6,[10,7,9],[1,2]],3,[[5,5,5],4,[0],0]],[6,[[2,0,2,10,2],9],[8,0,[5,5,1,7,6],[2,5,2],[]]],[[[4,5,5],2,5,[4,8]]],[10,4],[[3,[],1,3],[],[3,[9,7,0,1]]]]
[[[[9,9],9,6,8],3,[[],[],[10,8,6,7,6]],2],[[[0,5],4,7,[8,7,10],2],[[9,1],9,[4,9],6],2,5,[4,[7,6,6,4],3,8]],[[],[3,[7,7],1],10]]
[[9,[0,3,[0,6,9]],[[7,1],[4,4,3,1,9],10],1,3]]
[[8,7,8],[8,4,[]],[[[1],[4,9],[3]],6,8,[4,[6,3],[7],[1,0,10,7],10]],[2,2,0]]
[[2,10,2],[],[[[2,6,8,7],2],[7,[]]],[7,[[4]],9],[1,[3,[10,2]]]]
[[[],[]],[[3,5],[],10],[]]
[[2,6,6]]
[[8],[[4],[0,3,[]],[[8,6,0]],[10,10,8,1]],[[0,7],2,[0,10,[7,7,0,7,5],2],7],[[[2,5,7],6,4,10,2],7],[9]]
[[[9,[7,3],[9,7],1]],[[7,[6,4],1],[0],7,[]],[5,7,[[9,10,10],[10,2]]]]
[[8,[]],[[],[7,10,5,3,[5,8]],[],[[],4,2,8,[2,7,5,7,0]],[1,[9]]],[4,1,2,4,5]]
[[3,4,[]],[],[3,8,5,[4]]]
[[[5]],[],[],[[[3]],[[3,3,2,9,10],[0,6,5,7],9,2]]]
[[],[6,[10]],[[5,8,[5,7,4]],5,5],[1,[4,4,[],3,[4,1]],[[5,1,2,7],[10,6],2],[[7],0,0,[7],[1,4]],[8]]]
[[[[6,10,2],[],6,[5,1,1,1,1]],[8,2,[6,7],10,5],3],[6,[5,[9,4,3]]],[[[2,6,10],[0],9,9,[3]],9,5],[9,[9],[[4,4,10],10,6,[],[0,7]],[4,[8,1,9,5],[4]],[[0,3,7,7],[0,9,10,10]]]]
[[[],5,[3,[],9,[8,10]],2,6],[1,[6,[],6,[10,7,7,6],[3,7]],5],[7,10,[[8],[9,6],[],3,5],[[],4,2,8]],[[8,[]]],[8]]
[[9,4],[10,5],[[6,10,[0,1,1],0],7,4],[2,3,[7,8,1,1],6]]
[[],[[1,[2,1],5,[],9],6,[9,4,8],[[5,1,7],[10,1,8],0]],[8,1,[[],2,[2,8]]],[[3,[2,3,0],8,6,[]],[8,4,[8],[10,7,2,2,0]],9,1,[1,[0,8,7,1],2]],[[9,5],[[1,2],[],10,7],2]]
[[[10],6,7,4],[],[7,[0,9],[1,10,[0,10]],[[3,10],5,[9,9,8]]]]
[[[5,[0,8,0]],[[6,3,2,3,5],[8,4]],1],[[[6,6,6,2],1,[2,2],2],9,6,2],[]]
[[[],[],[[4,5],0],[10,6,7]],[[8,[9,8]]],[[[],[],3,7],[],0]]
[[],[7,4],[[5],5],[[],1,10,[0,[5,0,1,10,6],[8],1,[4]],0],[0]]
[[],[1,0,10],[]]
[[3,2,[[7,9,4,8,2],2,[1,0,9,6],10,[3,0]]],[[9,6],[[]],1,[[],5,[5,4]],[2]],[],[8,[[6],2]],[[]]]
[[0,[1],[],[[2]]],[[5,[1,0]],[[],2]],[4,[10,2,5],[[6,7,2,10,1],1,0,1]],[]]
[[0,[],[[5,3,5,3,0],[],[3,8,0,0,1],[2]]],[]]
[[[7,2],6,[8],[],[]]]
[[[10],0,0,[[0,9]]],[[0,4],[[2,9,1,3]],9],[2,[[]],[7,[0,8],8]],[6,[[6,9],10,[],[4,2],[0]]]]
[[8,[0,9]],[[2,6,8,[5],[8,1,1,9,4]],1,4],[[1,5],2]]
[[[10,[],9,7,6]],[1],[],[[8],10,[9],[]]]
[[[[9,7,7,7,0],[0,3,9,9,2],5],8,0,0],[],[[3,2,2,[2]],[2,[]],7],[[9,[7,8,9,9,10],[8,10]],6,10,[[]]],[]]

277
2022/day13/main.go Normal file
View File

@ -0,0 +1,277 @@
package main
import (
"fmt"
"math"
"sort"
"strings"
h "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func main() {
inp := h.StdinToStringSlice()
part1(inp)
fmt.Println()
part2(inp)
}
func part1(inp []string) {
commCount := 1
var result int
for i := 0; i < len(inp); i++ {
if inp[i] == "" {
commCount++
continue
}
pck1 := NewPacket(inp[i])
i++
pck2 := NewPacket(inp[i])
if !pck1.GreaterThan(pck2) {
result += commCount
}
}
fmt.Println("# Part 1")
fmt.Println("Sum:", result)
}
func part2(inp []string) {
var packets []*Packet
for i := 0; i < len(inp); i++ {
if inp[i] == "" {
continue
}
packets = append(packets, NewPacket(inp[i]))
}
div1, div2 := "[[2]]", "[[6]]"
var div1Idx, div2Idx int
packets = append(packets, NewPacket(div1))
packets = append(packets, NewPacket(div2))
sort.Slice(packets, func(i, j int) bool {
return packets[j].GreaterThan(packets[i])
})
for i := range packets {
if packets[i].raw == div1 {
div1Idx = i + 1
} else if packets[i].raw == div2 {
div2Idx = i + 1
}
}
fmt.Println("# Part 2")
fmt.Println("Decoder Key:", (div1Idx * div2Idx))
}
var outIndent int
var debug bool
func out(o string) {
if debug {
fmt.Printf("%s%s\n", strings.Repeat(" ", outIndent), o)
}
}
type Value struct {
raw string
Val int
List *ValueList
}
func NewValue() *Value {
return &Value{
Val: math.MinInt,
}
}
func (v *Value) Equals(v2 *Value) bool {
if v.IsInt() && v2.IsInt() {
return v.Val == v2.Val
} else if !v.IsInt() && !v2.IsInt() {
return v.List.Equals(v2.List)
} else {
// One is a list and the other is not
if v.IsInt() {
wrkV := NewValue()
wrkV.List = NewValueListFrom(v)
return wrkV.Equals(v2)
} else {
wrkV := NewValue()
wrkV.List = NewValueListFrom(v2)
return v.Equals(wrkV)
}
}
}
func (v *Value) GreaterThan(v2 *Value) bool {
outIndent++
if v.IsInt() && v2.IsInt() {
// Both are ints, which is greater?
out(fmt.Sprintf("Comparing: %v >? %v", v.Val, v2.Val))
outIndent--
return v.Val > v2.Val
} else if !v.IsInt() && !v2.IsInt() {
// Both are lists, check values in order
out(fmt.Sprintf("Comparing Lists: %v >? %v", v.List, v2.List))
tst := v.List.GreaterThan(v2.List)
outIndent--
return tst
} else {
// One is a list and the other is not
out(fmt.Sprintf("Comparing Different Types: %v >? %v", v, v2))
if v.IsInt() {
wrkV := NewValue()
wrkV.List = NewValueListFrom(v)
tst := wrkV.GreaterThan(v2)
outIndent--
return tst
} else {
wrkV := NewValue()
wrkV.List = NewValueListFrom(v2)
tst := v.GreaterThan(wrkV)
outIndent--
return tst
}
}
}
func (v *Value) IsInt() bool { return v.Val != math.MinInt }
func (v Value) String() string {
if v.Val != math.MinInt {
return fmt.Sprintf("{%d}", v.Val)
} else {
ret := "{["
for i := range *v.List {
ret = fmt.Sprintf("%s%s,", ret, (*v.List)[i].String())
}
ret = strings.TrimSuffix(ret, ",")
return fmt.Sprintf("%s]}", ret)
}
}
type ValueList []*Value
func NewValueListFrom(vals ...*Value) *ValueList {
ret := ValueList{}
for i := range vals {
ret.Add(vals[i])
}
return &ret
}
func (vl *ValueList) Add(v *Value) {
*vl = append(*vl, v)
}
func (vl *ValueList) Equals(vl2 *ValueList) bool {
wrk1, wrk2 := []*Value(*vl), []*Value(*vl2)
if len(wrk1) != len(wrk2) {
return false
}
for i := range wrk1 {
v1, v2 := wrk1[i], wrk2[i]
if !v1.Equals(v2) {
return false
}
}
return true
}
func (vl *ValueList) GreaterThan(vl2 *ValueList) bool {
wrk1, wrk2 := []*Value(*vl), []*Value(*vl2)
out(fmt.Sprintf("Comparing Lists: %v >? %v", wrk1, wrk2))
for i := range wrk1 {
var v1, v2 *Value
v1 = wrk1[i]
if len(wrk2) > i {
v2 = wrk2[i]
} else {
// vl is greater (has more items)
return true
}
if v1.GreaterThan(v2) {
out("v1 is greater than v2")
return true
} else if v2.GreaterThan(v1) {
return false
}
}
if len(wrk2) < len(wrk1) {
return true
}
return false
}
type Packet struct {
raw string
Val *Value
}
func (p *Packet) GreaterThan(p2 *Packet) bool {
return p.Val.GreaterThan(p2.Val)
}
func (p Packet) String() string {
return fmt.Sprintf("[%v]", p.Val)
}
func NewPacket(inp string) *Packet {
p := Packet{
raw: inp,
Val: NewValue(),
}
p.Val.List = ParsePacketList(inp)
return &p
}
func ParsePacketList(inp string) *ValueList {
if inp[0] != '[' {
return &ValueList{}
}
// parse all string tokens (at depth 1) through to the closing ']'
var tokens []string
tokenStart := 1
var depth int
for i := 0; i < len(inp); i++ {
if inp[i] == ',' && depth == 1 {
// Token break
tokens = append(tokens, inp[tokenStart:i])
tokenStart = i + 1
}
if inp[i] == '[' {
depth++
}
if inp[i] == ']' {
depth--
}
if depth == 0 {
if len(inp[tokenStart:i]) > 0 {
tokens = append(tokens, inp[tokenStart:i])
tokenStart = i + 1
}
break
}
}
// Now parse all tokens and add to the list
ret := NewValueListFrom()
for i := range tokens {
ret.Add(ParsePacketValue(tokens[i]))
}
return ret
}
// Parse a value out of the given string
func ParsePacketValue(inp string) *Value {
var rem string
v := NewValue()
if inp[0] == '[' {
// It's a list
list := ParsePacketList(inp)
v.raw = strings.TrimSuffix(inp, rem)
v.List = list
} else {
// It's an integer
sep := strings.IndexAny(inp, ",]")
var wrk string
if sep >= 0 {
wrk = inp[:sep]
rem = inp[sep+1:]
} else {
wrk = inp
rem = ""
}
v.Val = h.Atoi(wrk)
}
return v
}

203
2022/day13/problem Normal file
View File

@ -0,0 +1,203 @@
Advent of Code
br0xen (AoC++) 26*
--- Day 13: Distress Signal ---
You climb the hill and again try contacting the Elves. However, you instead receive a signal you
weren't expecting: a distress signal.
Your handheld device must still not be working properly; the packets from the distress signal
got decoded out of order. You'll need to re-order the list of received packets (your puzzle
input) to decode the message.
Your list consists of pairs of packets; pairs are separated by a blank line. You need to
identify how many pairs of packets are in the right order.
For example:
[1,1,3,1,1]
[1,1,5,1,1]
[[1],[2,3,4]]
[[1],4]
[9]
[[8,7,6]]
[[4,4],4,4]
[[4,4],4,4,4]
[7,7,7,7]
[7,7,7]
[]
[3]
[[[]]]
[[]]
[1,[2,[3,[4,[5,6,7]]]],8,9]
[1,[2,[3,[4,[5,6,0]]]],8,9]
Packet data consists of lists and integers. Each list starts with [, ends with ], and contains
zero or more comma-separated values (either integers or other lists). Each packet is always a
list and appears on its own line.
When comparing two values, the first value is called left and the second value is called right.
Then:
 If both values are integers, the lower integer should come first. If the left integer is
lower than the right integer, the inputs are in the right order. If the left integer is
higher than the right integer, the inputs are not in the right order. Otherwise, the inputs
are the same integer; continue checking the next part of the input.
 If both values are lists, compare the first value of each list, then the second value, and
so on. If the left list runs out of items first, the inputs are in the right order. If the
right list runs out of items first, the inputs are not in the right order. If the lists are
the same length and no comparison makes a decision about the order, continue checking the
next part of the input.
 If exactly one value is an integer, convert the integer to a list which contains that
integer as its only value, then retry the comparison. For example, if comparing [0,0,0] and
2, convert the right value to [2] (a list containing 2); the result is then found by instead
comparing [0,0,0] and [2].
Using these rules, you can determine which of the pairs in the example are in the right order:
== Pair 1 ==
- Compare [1,1,3,1,1] vs [1,1,5,1,1]
- Compare 1 vs 1
- Compare 1 vs 1
- Compare 3 vs 5
- Left side is smaller, so inputs are in the right order
== Pair 2 ==
- Compare [[1],[2,3,4]] vs [[1],4]
- Compare [1] vs [1]
- Compare 1 vs 1
- Compare [2,3,4] vs 4
- Mixed types; convert right to [4] and retry comparison
- Compare [2,3,4] vs [4]
- Compare 2 vs 4
- Left side is smaller, so inputs are in the right order
== Pair 3 ==
- Compare [9] vs [[8,7,6]]
- Compare 9 vs [8,7,6]
- Mixed types; convert left to [9] and retry comparison
- Compare [9] vs [8,7,6]
- Compare 9 vs 8
- Right side is smaller, so inputs are not in the right order
== Pair 4 ==
- Compare [[4,4],4,4] vs [[4,4],4,4,4]
- Compare [4,4] vs [4,4]
- Compare 4 vs 4
- Compare 4 vs 4
- Compare 4 vs 4
- Compare 4 vs 4
- Left side ran out of items, so inputs are in the right order
== Pair 5 ==
- Compare [7,7,7,7] vs [7,7,7]
- Compare 7 vs 7
- Compare 7 vs 7
- Compare 7 vs 7
- Right side ran out of items, so inputs are not in the right order
== Pair 6 ==
- Compare [] vs [3]
- Left side ran out of items, so inputs are in the right order
== Pair 7 ==
- Compare [[[]]] vs [[]]
- Compare [[]] vs []
- Right side ran out of items, so inputs are not in the right order
== Pair 8 ==
- Compare [1,[2,[3,[4,[5,6,7]]]],8,9] vs [1,[2,[3,[4,[5,6,0]]]],8,9]
- Compare 1 vs 1
- Compare [2,[3,[4,[5,6,7]]]] vs [2,[3,[4,[5,6,0]]]]
- Compare 2 vs 2
- Compare [3,[4,[5,6,7]]] vs [3,[4,[5,6,0]]]
- Compare 3 vs 3
- Compare [4,[5,6,7]] vs [4,[5,6,0]]
- Compare 4 vs 4
- Compare [5,6,7] vs [5,6,0]
- Compare 5 vs 5
- Compare 6 vs 6
- Compare 7 vs 0
- Right side is smaller, so inputs are not in the right order
What are the indices of the pairs that are already in the right order? (The first pair has index
1, the second pair has index 2, and so on.) In the above example, the pairs in the right order
are 1, 2, 4, and 6; the sum of these indices is 13.
Determine which pairs of packets are already in the right order. What is the sum of the indices
of those pairs?
Your puzzle answer was 5905.
--- Part Two ---
Now, you just need to put all of the packets in the right order. Disregard the blank lines in
your list of received packets.
The distress signal protocol also requires that you include two additional divider packets:
[[2]]
[[6]]
Using the same rules as before, organize all packets - the ones in your list of received packets
as well as the two divider packets - into the correct order.
For the example above, the result of putting the packets in the correct order is:
[]
[[]]
[[[]]]
[1,1,3,1,1]
[1,1,5,1,1]
[[1],[2,3,4]]
[1,[2,[3,[4,[5,6,0]]]],8,9]
[1,[2,[3,[4,[5,6,7]]]],8,9]
[[1],4]
[[2]]
[3]
[[4,4],4,4]
[[4,4],4,4,4]
[[6]]
[7,7,7]
[7,7,7,7]
[[8,7,6]]
[9]
Afterward, locate the divider packets. To find the decoder key for this distress signal, you
need to determine the indices of the two divider packets and multiply them together. (The first
packet is at index 1, the second packet is at index 2, and so on.) In this example, the divider
packets are 10th and 14th, and so the decoder key is 140.
Organize all of the packets into the correct order. What is the decoder key for the distress
signal?
Your puzzle answer was 21691.
Both parts of this puzzle are complete! They provide two gold stars: **
References
Visible links
. https://adventofcode.com/
. https://adventofcode.com/2022/about
. https://adventofcode.com/2022/events
. https://adventofcode.com/2022/settings
. https://adventofcode.com/2022/auth/logout
. Advent of Code Supporter
https://adventofcode.com/2022/support
. https://adventofcode.com/2022
. https://adventofcode.com/2022
. https://adventofcode.com/2022/support
. https://adventofcode.com/2022/sponsors
. https://adventofcode.com/2022/leaderboard
. https://adventofcode.com/2022/stats
. https://adventofcode.com/2022/sponsors
. https://adventofcode.com/2022
. https://adventofcode.com/2022/day/13/input

23
2022/day13/testinput Normal file
View File

@ -0,0 +1,23 @@
[1,1,3,1,1]
[1,1,5,1,1]
[[1],[2,3,4]]
[[1],4]
[9]
[[8,7,6]]
[[4,4],4,4]
[[4,4],4,4,4]
[7,7,7,7]
[7,7,7]
[]
[3]
[[[]]]
[[]]
[1,[2,[3,[4,[5,6,7]]]],8,9]
[1,[2,[3,[4,[5,6,0]]]],8,9]

View File

@ -42,6 +42,9 @@ func (c *Coordinate) SW() Coordinate {
func (c *Coordinate) SE() Coordinate {
return Coordinate{X: c.X + 1, Y: c.Y + 1}
}
func (c *Coordinate) GetOrthNeighbors() []Coordinate {
return []Coordinate{c.North(), c.East(), c.South(), c.West()}
}
func (c *Coordinate) GetNorthCoord() *Coordinate {
return &Coordinate{

View File

@ -35,6 +35,24 @@ func StringSliceToCoordByteMap(input []string) CoordByteMap {
return ret
}
func (m *CoordByteMap) ToByteSlices() [][]byte {
var ret [][]byte
for y := m.TLY; y <= m.BRY; y++ {
var line []byte
for x := m.TLX; x <= m.BRX; x++ {
line = append(line, m.Get(Coordinate{X: x, Y: y}))
}
ret = append(ret, line)
}
return ret
}
// ContainsCoord returns true if the passed coordinate is in 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
}
// FindFirst searches left to right, top to bottom for the first
// instance of b.
func (m *CoordByteMap) FindFirst(b byte) (Coordinate, error) {
@ -85,6 +103,52 @@ func (m *CoordByteMap) FindAllNot(b ...byte) map[Coordinate]byte {
return ret
}
// FindAdjacentOrth takes a coordinate and a desired byte, and returns
// all adjacent coordinates that contain that byte
func (m *CoordByteMap) FindAdjacent(st Coordinate, val byte) []Coordinate {
return m.AnyContain([]Coordinate{st.North(), st.NE(), st.East(), st.SE(), st.South(), st.SW(), st.West(), st.NW()}, val)
}
// FindAdjacentOrth takes a coordinate and a desired byte, and returns
// all adjacent coordinates that contain that byte, Orthogonally
func (m *CoordByteMap) FindAdjacentOrth(st Coordinate, val byte) []Coordinate {
return m.AnyContain([]Coordinate{st.North(), st.East(), st.South(), st.West()}, val)
}
func (m *CoordByteMap) AnyContain(check []Coordinate, val byte) []Coordinate {
var ret []Coordinate
for _, wrk := range check {
if m.Get(wrk) == val {
ret = append(ret, wrk)
}
}
return ret
}
// FindAnyAdjacentOrth takes a coordinate and a list of desired bytes, and returns
// all adjacent coordinates that contain those bytes
func (m *CoordByteMap) FindAnyAdjacent(st Coordinate, val []byte) []Coordinate {
return m.AnyContainAny([]Coordinate{st.North(), st.NE(), st.East(), st.SE(), st.South(), st.SW(), st.West(), st.NW()}, val)
}
// FindAnyAdjacentOrth takes a coordinate and a desired byte, and returns
// all adjacent coordinates that contain that byte, Orthogonally
func (m *CoordByteMap) FindAnyAdjacentOrth(st Coordinate, val []byte) []Coordinate {
return m.AnyContainAny([]Coordinate{st.North(), st.East(), st.South(), st.West()}, val)
}
func (m *CoordByteMap) AnyContainAny(check []Coordinate, val []byte) []Coordinate {
var ret []Coordinate
for _, wrk := range check {
for _, bt := range val {
if m.Get(wrk) == bt {
ret = append(ret, wrk)
}
}
}
return ret
}
func (m *CoordByteMap) Count(b byte) int {
var ret int
for y := m.TLY; y <= m.BRY; y++ {