You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.0 KiB
92 lines
2.0 KiB
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"bytes"
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"unicode"
|
|
)
|
|
|
|
type groundpipe struct {
|
|
value byte // value of the pipe
|
|
|
|
// byte slices should be sorted to allow for easier comparison
|
|
north []byte // valid byte set for a pipe to the north
|
|
south []byte // valid byte set for a pipe to the south
|
|
east []byte // valid byte set for a pipe to the east
|
|
west []byte // valid byte set for a pipe to the west
|
|
}
|
|
|
|
type day10 struct{}
|
|
|
|
func scanmaze(r io.Reader) ([][]groundpipe, int, int) {
|
|
layers := make([][]groundpipe, 0)
|
|
row, col := 0, 0
|
|
buf := bufio.NewReader(r)
|
|
|
|
for next := true; next; {
|
|
bts, err := buf.ReadBytes('\n')
|
|
next = !reachedeof(err)
|
|
|
|
layers = append(layers, make([]groundpipe, 0))
|
|
end := len(layers) - 1
|
|
|
|
for i, b := range bytes.TrimFunc(bts, unicode.IsSpace) {
|
|
pipe := groundpipe{value: b}
|
|
switch b {
|
|
case '|':
|
|
pipe.north = []byte("7F|")
|
|
pipe.south = []byte("JL|")
|
|
// pipe.east = []byte("")
|
|
// pipe.west = []byte("")
|
|
case '-':
|
|
// pipe.north = []byte("")
|
|
// pipe.south = []byte("")
|
|
pipe.east = []byte("-7J")
|
|
pipe.west = []byte("-FL")
|
|
case 'L':
|
|
pipe.north = []byte("7F|")
|
|
// pipe.south = []byte("")
|
|
pipe.east = []byte("-7J")
|
|
// pipe.west = []byte("")
|
|
case 'J':
|
|
pipe.north = []byte("7F|")
|
|
// pipe.south = []byte("")
|
|
// pipe.east = []byte("")
|
|
pipe.west = []byte("-FL")
|
|
case '7':
|
|
// pipe.north = []byte("")
|
|
pipe.south = []byte("JL|")
|
|
// pipe.east = []byte("")
|
|
pipe.west = []byte("-FL")
|
|
case 'F':
|
|
// pipe.north = []byte("")
|
|
pipe.south = []byte("JL|")
|
|
pipe.east = []byte("-7J")
|
|
// pipe.west = []byte("")
|
|
case 'S':
|
|
row, col = end, i
|
|
default:
|
|
// ignoring '.' and '\n'
|
|
continue
|
|
}
|
|
layers[end] = append(layers[end], pipe)
|
|
}
|
|
}
|
|
|
|
return layers, row, col
|
|
}
|
|
|
|
func (d day10) solve1(r io.Reader) string {
|
|
_, startx, starty := scanmaze(r)
|
|
log.Printf("x: %d; y: %d", startx, starty)
|
|
farthest := 0
|
|
|
|
return fmt.Sprintf("%d", farthest)
|
|
}
|
|
|
|
func (d day10) solve2(r io.Reader) string {
|
|
return "incomplete"
|
|
}
|
|
|