From 928043028520df5a1b37790eb2b409c468958b7c Mon Sep 17 00:00:00 2001 From: Kharec Date: Thu, 4 Dec 2025 06:45:40 +0100 Subject: [PATCH] feat: solve part one using prebuilt map for rolls --- internal/2025/DayFour/code.go | 65 +++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 internal/2025/DayFour/code.go diff --git a/internal/2025/DayFour/code.go b/internal/2025/DayFour/code.go new file mode 100644 index 0000000..418820d --- /dev/null +++ b/internal/2025/DayFour/code.go @@ -0,0 +1,65 @@ +package dayfour + +import ( + "os" + "strings" + + "advent-of-code/internal/registry" +) + +type position struct { + row, column int +} + +func init() { + registry.Register("2025D4", ParseInput, PartOne, PartTwo) +} + +func ParseInput(filepath string) []string { + content, _ := os.ReadFile(filepath) + return strings.Split(string(content), "\n") +} + +func PartOne(data []string) int { + rollPositions := make(map[position]bool) + + for row := range data { + for column := 0; column < len(data[row]); column++ { + if data[row][column] == '@' { + rollPositions[position{row, column}] = true + } + } + } + + accessibleRolls := 0 + directions := []position{ + {-1, -1}, + {-1, 0}, + {-1, 1}, + {0, -1}, + {0, 1}, + {1, -1}, + {1, 0}, + {1, 1}, + } + + for pos := range rollPositions { + adjacentRolls := 0 + for _, direction := range directions { + neighbor := position{pos.row + direction.row, pos.column + direction.column} + if rollPositions[neighbor] { + adjacentRolls++ + } + } + + if adjacentRolls < 4 { + accessibleRolls++ + } + } + + return accessibleRolls +} + +func PartTwo(data []string) int { + return 0 +}