Alexander Avery
1 year ago
3 changed files with 104 additions and 2 deletions
@ -0,0 +1,92 @@ |
|||||
|
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" |
||||
|
} |
Loading…
Reference in new issue