74 lines
1.3 KiB
Go
74 lines
1.3 KiB
Go
package dayseven
|
|
|
|
import (
|
|
"advent-of-code/internal/registry"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func init() {
|
|
registry.Register("2025D7", ParseInput, PartOne, PartTwo)
|
|
}
|
|
|
|
type Position struct {
|
|
row int
|
|
column int
|
|
}
|
|
|
|
func ParseInput(filepath string) []string {
|
|
content, _ := os.ReadFile(filepath)
|
|
return strings.Split(string(content), "\n")
|
|
}
|
|
|
|
func findStart(input []string) (int, int) {
|
|
for row := range input {
|
|
if column := strings.IndexByte(input[row], 'S'); column != -1 {
|
|
return row, column
|
|
}
|
|
}
|
|
return -1, -1
|
|
}
|
|
|
|
func PartOne(input []string) int {
|
|
rows, columns := len(input), len(input[0])
|
|
|
|
startRow, startColumn := findStart(input)
|
|
|
|
queue := []Position{{startRow, startColumn}}
|
|
activated := make(map[Position]bool)
|
|
splits := 0
|
|
|
|
for len(queue) > 0 {
|
|
current := queue[0]
|
|
queue = queue[1:]
|
|
|
|
row := current.row + 1
|
|
column := current.column
|
|
|
|
for row < rows && input[row][column] != '^' {
|
|
row++
|
|
}
|
|
|
|
if row < rows {
|
|
splitPosition := Position{row, column}
|
|
if !activated[splitPosition] {
|
|
activated[splitPosition] = true
|
|
splits++
|
|
|
|
if column > 0 {
|
|
queue = append(queue, Position{row, column - 1})
|
|
}
|
|
if column < columns-1 {
|
|
queue = append(queue, Position{row, column + 1})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return splits
|
|
}
|
|
|
|
func PartTwo(data []string) int {
|
|
return 0
|
|
}
|