From 2b548fa1efc952e04e33317e1f3e3650bc3b26ca Mon Sep 17 00:00:00 2001 From: Kharec Date: Thu, 4 Dec 2025 16:49:43 +0100 Subject: [PATCH] feat: solve part one with pruned bruteforce --- internal/2015/DayEleven/code.go | 89 +++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 internal/2015/DayEleven/code.go diff --git a/internal/2015/DayEleven/code.go b/internal/2015/DayEleven/code.go new file mode 100644 index 0000000..75b2eb6 --- /dev/null +++ b/internal/2015/DayEleven/code.go @@ -0,0 +1,89 @@ +package dayeleven + +import ( + "os" + + "advent-of-code/internal/registry" +) + +func init() { + registry.Register("2015D11", ParseInput, PartOne, PartTwo) +} + +func ParseInput(filepath string) string { + content, _ := os.ReadFile(filepath) + return string(content) +} + +func PartOne(data string) int { + bytes := []byte(data) + + increment := func() { + for idx := len(bytes) - 1; idx >= 0; idx-- { + if bytes[idx] == 'z' { + bytes[idx] = 'a' + } else { + bytes[idx]++ + if bytes[idx] == 'i' || bytes[idx] == 'o' || bytes[idx] == 'l' { + bytes[idx]++ + } + for j := idx + 1; j < len(bytes); j++ { + bytes[j] = 'a' + } + return + } + } + } + + increment() + + for { + forbiddenPosition := -1 + for idx := range bytes { + if bytes[idx] == 'i' || bytes[idx] == 'o' || bytes[idx] == 'l' { + forbiddenPosition = idx + break + } + } + + if forbiddenPosition != -1 { + bytes[forbiddenPosition]++ + if bytes[forbiddenPosition] == 'i' || bytes[forbiddenPosition] == 'o' || bytes[forbiddenPosition] == 'l' { + bytes[forbiddenPosition]++ + } + for j := forbiddenPosition + 1; j < len(bytes); j++ { + bytes[j] = 'a' + } + continue + } + + hasStraight := false + for idx := 0; idx < len(bytes)-2; idx++ { + if bytes[idx+1] == bytes[idx]+1 && bytes[idx+2] == bytes[idx]+2 { + hasStraight = true + break + } + } + + pairChars := make(map[byte]bool) + for idx := 0; idx < len(bytes)-1; idx++ { + if bytes[idx] == bytes[idx+1] { + pairChars[bytes[idx]] = true + idx++ + } + } + + if hasStraight && len(pairChars) >= 2 { + break + } + + increment() + } + + println(string(bytes)) + return 0 +} + +func PartTwo(data string) int { + return 0 +}