From 78b0032578923cbedd0ff5593fd04c7fc63aca23 Mon Sep 17 00:00:00 2001 From: Kharec Date: Sun, 7 Dec 2025 09:54:53 +0100 Subject: [PATCH] feat: solve PartOne using DFS algorithm --- internal/2025/DaySeven/code.go | 73 ++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 internal/2025/DaySeven/code.go diff --git a/internal/2025/DaySeven/code.go b/internal/2025/DaySeven/code.go new file mode 100644 index 0000000..6e87bcb --- /dev/null +++ b/internal/2025/DaySeven/code.go @@ -0,0 +1,73 @@ +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 +}