2019 Day 18 started
This commit is contained in:
77
2019/day18/main.go
Normal file
77
2019/day18/main.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
helpers "git.bullercodeworks.com/brian/adventofcode/helpers"
|
||||
)
|
||||
|
||||
var maxX, maxY int
|
||||
var vault map[helpers.Coordinate]byte
|
||||
var keys map[helpers.Coordinate]byte
|
||||
var doors map[helpers.Coordinate]byte
|
||||
|
||||
func main() {
|
||||
file := "input"
|
||||
if helpers.GetArgNumber(1) != "" {
|
||||
file = helpers.GetArgNumber(1)
|
||||
}
|
||||
inp := helpers.FileToBytes(file)
|
||||
wrk := bytes.Split(inp, []byte{'\n'})
|
||||
maxY = len(wrk)
|
||||
vault = make(map[helpers.Coordinate]byte)
|
||||
keys = make(map[helpers.Coordinate]byte)
|
||||
doors = make(map[helpers.Coordinate]byte)
|
||||
maxX = len(wrk[0])
|
||||
for y, yv := range wrk {
|
||||
for x, xv := range yv {
|
||||
vault[*helpers.NewCoordinate(x, y)] = xv
|
||||
if isKey(xv) {
|
||||
keys[*helpers.NewCoordinate(x, y)] = xv
|
||||
} else if isDoor(xv) {
|
||||
doors[*helpers.NewCoordinate(x, y)] = xv
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PrintVault()
|
||||
}
|
||||
|
||||
func isDoor(b byte) bool {
|
||||
return b >= 'A' && b <= 'Z'
|
||||
}
|
||||
func isKey(b byte) bool {
|
||||
return b >= 'a' && b <= 'z'
|
||||
}
|
||||
|
||||
func keyToDoor(b byte) byte {
|
||||
return (b - 'a') + 'A'
|
||||
}
|
||||
|
||||
func doorToKey(b byte) byte {
|
||||
return (b - 'A') + 'a'
|
||||
}
|
||||
|
||||
func findKey(b byte) (helpers.Coordinate, error) {
|
||||
var r helpers.Coordinate
|
||||
if !isDoor(b) {
|
||||
return r, errors.New("Invalid Door")
|
||||
}
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func PrintVault() {
|
||||
for y := 0; y < maxY; y++ {
|
||||
for x := 0; x < maxX; x++ {
|
||||
fmt.Print(string(vault[*helpers.NewCoordinate(x, y)]))
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
|
||||
func c(x, y int) string {
|
||||
return fmt.Sprintf("[%d, %d]", x, y)
|
||||
}
|
||||
Reference in New Issue
Block a user