Compare commits

..

No commits in common. "51fed356af2c77616b5ca45fe639279c7cd6f680" and "4013cd6c7fea0d22c713e48c080925e8deb67b4d" have entirely different histories.

4 changed files with 22 additions and 16 deletions

View File

@ -20,6 +20,10 @@ func Solve(buf []byte) (int, error) {
current := newPoint(j, i)
if graph.valueAt(current) == 'X' {
for _, n := range neighbours(current) {
if graph.isOutOfBounds(n) {
continue
}
if checkNeighbours(graph, n, "MAS") {
sum++
}

View File

@ -4,21 +4,21 @@ import (
"strings"
)
type kind int
type kindOfSchematic int
const (
kindOfLock kind = iota
kindOfKey
Lock kindOfSchematic = iota
Key
)
type schematic struct {
kind kind
kind kindOfSchematic
heights []int
data []string
}
func newSchematic(buf [][]byte) *schematic {
var kind kind
var kind kindOfSchematic
data := make([]string, len(buf))
heights := make([]int, len(buf[0]))
@ -26,15 +26,17 @@ func newSchematic(buf [][]byte) *schematic {
data[i] = string(line)
if i == 0 {
switch {
case allInString(data[i], '#'):
kind = kindOfLock
case allInString(data[i], '.'):
kind = kindOfKey
if allInString(data[i], '#') {
kind = Lock
} else if allInString(data[i], '.') {
kind = Key
}
}
if (kind == kindOfLock && i == 0) || (kind == kindOfKey && i == len(buf)-1) {
if kind == Lock && i == 0 {
continue
}
if kind == Key && i == len(buf)-1 {
continue
}

View File

@ -14,8 +14,8 @@ func Solve(buf []byte) (int, error) {
}
var count int
for _, lock := range schematics[kindOfLock] {
for _, key := range schematics[kindOfKey] {
for _, lock := range schematics[Lock] {
for _, key := range schematics[Key] {
if func() bool {
for i := range key.heights {
if key.heights[i]+lock.heights[i] > maxHeight {

View File

@ -5,17 +5,17 @@ import (
"io"
)
func parseLines(r io.Reader) (int, map[kind][]*schematic, error) {
func parseLines(r io.Reader) (int, map[kindOfSchematic][]*schematic, error) {
raw, _ := io.ReadAll(r)
rawSchematics := bytes.Split(raw, []byte("\n\n"))
schematics := map[kind][]*schematic{kindOfLock: {}, kindOfKey: {}}
schematics := map[kindOfSchematic][]*schematic{Lock: {}, Key: {}}
for _, rawSchematic := range rawSchematics {
s := newSchematic(bytes.Split(rawSchematic, []byte("\n")))
schematics[s.kind] = append(schematics[s.kind], s)
}
maxHeight := len(schematics[kindOfLock][0].heights)
maxHeight := len(schematics[Lock][0].heights)
return maxHeight, schematics, nil
}