2021 Day 23 is complete, but not by code...
This commit is contained in:
5
2021/day23/input
Normal file
5
2021/day23/input
Normal file
@@ -0,0 +1,5 @@
|
||||
#############
|
||||
#...........#
|
||||
###A#C#B#C###
|
||||
#D#A#D#B#
|
||||
#########
|
77
2021/day23/main.go
Normal file
77
2021/day23/main.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
h "git.bullercodeworks.com/brian/adventofcode/helpers"
|
||||
)
|
||||
|
||||
var costs map[byte]int
|
||||
var homes map[byte][]h.Coordinate
|
||||
var burrow h.CoordByteMap
|
||||
|
||||
func main() {
|
||||
costs = map[byte]int{'A': 1, 'B': 10, 'C': 100, 'D': 1000}
|
||||
homes = map[byte][]h.Coordinate{
|
||||
'A': []h.Coordinate{h.Coordinate{X: 3, Y: 3}, h.Coordinate{X: 3, Y: 2}},
|
||||
'B': []h.Coordinate{h.Coordinate{X: 5, Y: 3}, h.Coordinate{X: 5, Y: 2}},
|
||||
'C': []h.Coordinate{h.Coordinate{X: 7, Y: 3}, h.Coordinate{X: 7, Y: 2}},
|
||||
'D': []h.Coordinate{h.Coordinate{X: 9, Y: 3}, h.Coordinate{X: 9, Y: 2}},
|
||||
}
|
||||
inp := h.StdinToStringSlice()
|
||||
burrow = h.StringSliceToCoordByteMap(inp)
|
||||
fmt.Println(burrow)
|
||||
pods := findAllPods()
|
||||
for k, v := range pods {
|
||||
fmt.Println(k, string(v))
|
||||
}
|
||||
}
|
||||
|
||||
func findAllPods() map[h.Coordinate]byte {
|
||||
return burrow.FindAllNot(' ', '#', '.')
|
||||
}
|
||||
|
||||
func getHome(b byte) h.Coordinate {
|
||||
// Returns the home spot for this pod...
|
||||
if burrow.Get(homes[b][0]) == b {
|
||||
return homes[b][1]
|
||||
}
|
||||
return homes[b][0]
|
||||
}
|
||||
func isPod(b byte) bool {
|
||||
return b == 'A' || b == 'B' || b == 'C' || b == 'd'
|
||||
}
|
||||
|
||||
// pathClear checks:
|
||||
// 1: is the given coordinate a pod?
|
||||
// 2: is the path to the pod's home clear?
|
||||
func pathClear(c h.Coordinate) bool {
|
||||
v := burrow.Get(c)
|
||||
if !isPod(v) {
|
||||
return false
|
||||
}
|
||||
return canMoveFromTo(c, getHome(v))
|
||||
}
|
||||
|
||||
func canMoveFromTo(from, to h.Coordinate) bool {
|
||||
if from.Equals(to) { // Not actually moving...
|
||||
return true
|
||||
}
|
||||
if burrow.Get(to) != '.' {
|
||||
return false
|
||||
}
|
||||
if from.X == to.X {
|
||||
// Just moving up or down
|
||||
if from.Y > to.Y {
|
||||
return canMoveFromTo(h.Coordinate{X: from.X, Y: from.Y - 1}, to)
|
||||
}
|
||||
return canMoveFromTo(h.Coordinate{X: from.X, Y: from.Y + 1}, to)
|
||||
} else if from.Y == to.Y {
|
||||
// Just moving left or right
|
||||
if from.X > to.X {
|
||||
return canMoveFromTo(h.Coordinate{X: from.X - 1, Y: from.Y}, to)
|
||||
}
|
||||
return canMoveFromTo(h.Coordinate{X: from.X + 1, Y: from.Y}, to)
|
||||
}
|
||||
|
||||
}
|
5
2021/day23/testinput
Normal file
5
2021/day23/testinput
Normal file
@@ -0,0 +1,5 @@
|
||||
#############
|
||||
#...........#
|
||||
###B#C#B#D###
|
||||
#A#D#C#A#
|
||||
#########
|
22
2021/day23/work
Normal file
22
2021/day23/work
Normal file
@@ -0,0 +1,22 @@
|
||||
{'A': 1, 'B': 10, 'C': 100, 'D': 1000}
|
||||
|
||||
#############
|
||||
#...........#
|
||||
###A#B#C#.###
|
||||
#A#B#C#D#
|
||||
#########
|
||||
|
||||
A: 7, 2, 3, 7
|
||||
B: 5, 7, 3, 3
|
||||
C: 11
|
||||
D Min: 15
|
||||
|
||||
// 16277 is too low?
|
||||
// 16330 is incorrect
|
||||
// 16442 is too high
|
||||
// 16512 is too high
|
||||
|
||||
A: 2, 6, 2
|
||||
B: 4, 4, 7, 7
|
||||
C: 4, 3, 4 (C Min: 9)
|
||||
D Min: 15
|
Reference in New Issue
Block a user