From 33552358f83134771b690f38918e941500230f18 Mon Sep 17 00:00:00 2001 From: Kharec Date: Tue, 2 Dec 2025 06:52:30 +0100 Subject: [PATCH] feat: solve p1 --- internal/2025/DayTwo/code.go | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 internal/2025/DayTwo/code.go diff --git a/internal/2025/DayTwo/code.go b/internal/2025/DayTwo/code.go new file mode 100644 index 0000000..d868fad --- /dev/null +++ b/internal/2025/DayTwo/code.go @@ -0,0 +1,47 @@ +package daytwo + +import ( + "advent-of-code/internal/registry" + "os" + "strconv" + "strings" +) + +func init() { + registry.Register("2025D2", ParseInput, PartOne, PartTwo) +} + +func isInvalidID(id int) bool { + sID := strconv.Itoa(id) + if len(sID)%2 != 0 { + return false + } + half := len(sID) / 2 + return sID[:half] == sID[half:] +} + +func ParseInput(filepath string) []string { + content, _ := os.ReadFile(filepath) + return strings.Split(strings.TrimSpace(string(content)), "\n") +} + +func PartOne(input []string) int { + sum := 0 + for _, line := range input { + for newRange := range strings.SplitSeq(line, ",") { + parts := strings.Split(newRange, "-") + start, _ := strconv.Atoi(parts[0]) + end, _ := strconv.Atoi(parts[1]) + for id := start; id <= end; id++ { + if isInvalidID(id) { + sum += id + } + } + } + } + return sum +} + +func PartTwo(input []string) int { + return 0 +}