mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-04-18 10:43:47 +01:00
Compare commits
No commits in common. "51fed356af2c77616b5ca45fe639279c7cd6f680" and "4013cd6c7fea0d22c713e48c080925e8deb67b4d" have entirely different histories.
51fed356af
...
4013cd6c7f
@ -20,6 +20,10 @@ func Solve(buf []byte) (int, error) {
|
|||||||
current := newPoint(j, i)
|
current := newPoint(j, i)
|
||||||
if graph.valueAt(current) == 'X' {
|
if graph.valueAt(current) == 'X' {
|
||||||
for _, n := range neighbours(current) {
|
for _, n := range neighbours(current) {
|
||||||
|
if graph.isOutOfBounds(n) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if checkNeighbours(graph, n, "MAS") {
|
if checkNeighbours(graph, n, "MAS") {
|
||||||
sum++
|
sum++
|
||||||
}
|
}
|
||||||
|
@ -4,21 +4,21 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type kind int
|
type kindOfSchematic int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
kindOfLock kind = iota
|
Lock kindOfSchematic = iota
|
||||||
kindOfKey
|
Key
|
||||||
)
|
)
|
||||||
|
|
||||||
type schematic struct {
|
type schematic struct {
|
||||||
kind kind
|
kind kindOfSchematic
|
||||||
heights []int
|
heights []int
|
||||||
data []string
|
data []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSchematic(buf [][]byte) *schematic {
|
func newSchematic(buf [][]byte) *schematic {
|
||||||
var kind kind
|
var kind kindOfSchematic
|
||||||
data := make([]string, len(buf))
|
data := make([]string, len(buf))
|
||||||
heights := make([]int, len(buf[0]))
|
heights := make([]int, len(buf[0]))
|
||||||
|
|
||||||
@ -26,15 +26,17 @@ func newSchematic(buf [][]byte) *schematic {
|
|||||||
data[i] = string(line)
|
data[i] = string(line)
|
||||||
|
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
switch {
|
if allInString(data[i], '#') {
|
||||||
case allInString(data[i], '#'):
|
kind = Lock
|
||||||
kind = kindOfLock
|
} else if allInString(data[i], '.') {
|
||||||
case allInString(data[i], '.'):
|
kind = Key
|
||||||
kind = kindOfKey
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ func Solve(buf []byte) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var count int
|
var count int
|
||||||
for _, lock := range schematics[kindOfLock] {
|
for _, lock := range schematics[Lock] {
|
||||||
for _, key := range schematics[kindOfKey] {
|
for _, key := range schematics[Key] {
|
||||||
if func() bool {
|
if func() bool {
|
||||||
for i := range key.heights {
|
for i := range key.heights {
|
||||||
if key.heights[i]+lock.heights[i] > maxHeight {
|
if key.heights[i]+lock.heights[i] > maxHeight {
|
||||||
|
@ -5,17 +5,17 @@ import (
|
|||||||
"io"
|
"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)
|
raw, _ := io.ReadAll(r)
|
||||||
rawSchematics := bytes.Split(raw, []byte("\n\n"))
|
rawSchematics := bytes.Split(raw, []byte("\n\n"))
|
||||||
|
|
||||||
schematics := map[kind][]*schematic{kindOfLock: {}, kindOfKey: {}}
|
schematics := map[kindOfSchematic][]*schematic{Lock: {}, Key: {}}
|
||||||
for _, rawSchematic := range rawSchematics {
|
for _, rawSchematic := range rawSchematics {
|
||||||
s := newSchematic(bytes.Split(rawSchematic, []byte("\n")))
|
s := newSchematic(bytes.Split(rawSchematic, []byte("\n")))
|
||||||
schematics[s.kind] = append(schematics[s.kind], s)
|
schematics[s.kind] = append(schematics[s.kind], s)
|
||||||
}
|
}
|
||||||
|
|
||||||
maxHeight := len(schematics[kindOfLock][0].heights)
|
maxHeight := len(schematics[Lock][0].heights)
|
||||||
|
|
||||||
return maxHeight, schematics, nil
|
return maxHeight, schematics, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user