2020 Day 19 & 20 Complete

This commit is contained in:
2020-12-20 15:57:10 -06:00
parent 069d03004d
commit e9e89e0a42
8 changed files with 2661 additions and 244 deletions

View File

@@ -26,7 +26,9 @@ func init() {
}
for y := range monster {
for x := range monster[y] {
SeaMonster[h.Coordinate{X: x, Y: y}] = monster[y][x] == '#'
if monster[y][x] == '#' {
SeaMonster[h.Coordinate{X: x, Y: y}] = true
}
}
}
}
@@ -58,12 +60,8 @@ func solve(inp []string, part int) {
for x := range image[y] {
if image[y][x] {
waves++
fmt.Print("#")
} else {
fmt.Print(" ")
}
}
fmt.Println()
}
fmt.Println("## Part2\nAnswer:", waves)
}
@@ -200,11 +198,6 @@ func buildMapFromTiles(tiles map[int]*Tile) [][]bool {
func monsterSlayer(inp [][]bool) [][]bool {
var found bool
for r := 0; r < 8; r++ {
if r == 6 {
// This is the correct orientation
fmt.Println("Rotation:", r)
PrintMap(inp)
}
for y := range inp {
for x := range inp[y] {
match := true
@@ -232,7 +225,6 @@ func monsterSlayer(inp [][]bool) [][]bool {
}
}
if found {
fmt.Println("Found, breaking")
break
}
if r&1 == 0 {
@@ -284,3 +276,39 @@ func PrintMap(inp [][]bool) {
fmt.Println()
}
}
func PrintCoordMap(m map[h.Coordinate]bool) {
minX := h.MAX_INT
maxX := h.MIN_INT
minY := h.MAX_INT
maxY := h.MIN_INT
for k := range m {
if k.X < minX {
minX = k.X
}
if k.X > maxX {
maxX = k.X
}
if k.Y < minY {
minY = k.Y
}
if k.Y > maxY {
maxY = k.Y
}
}
for y := minY; y <= maxY; y++ {
for x := minX; x <= maxX; x++ {
if v, ok := m[h.Coordinate{X: x, Y: y}]; ok {
if v {
fmt.Print("#")
} else {
fmt.Print(".")
}
} else {
fmt.Print(".")
}
}
fmt.Println()
}
}