Compare commits

...

2 Commits

  1. 4
      day09.go
  2. 92
      day10.go
  3. 1
      main.go
  4. 13
      main_test.go

4
day09.go

@ -30,10 +30,6 @@ func nextOasis(previous int, start []int) int {
return current + nextOasis(current, levelBelow)
}
func previousOasis(previous int, start []int) int {
return 0
}
type day09 struct{}
func (d day09) solve1(r io.Reader) string {

92
day10.go

@ -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"
}

1
main.go

@ -29,6 +29,7 @@ var (
&day07{},
&day08{},
&day09{},
&day10{},
}
)

13
main_test.go

@ -163,10 +163,19 @@ ZZZ = (ZZZ, ZZZ)`,
{
// day 9
inp1: `0 3 6 9 12 15
1 3 6 10 15 21
10 13 16 21 30 45`,
1 3 6 10 15 21
10 13 16 21 30 45`,
ans1: "114",
ans2: "2",
},
{
// day 10
inp1: `..F7.
.FJ|.
SJ.L7
|F--J
LJ...`,
ans1: "8",
},
}
)

Loading…
Cancel
Save