From aa80e4eb8ef37ecc7b75ba7f51bf41084a338c6d Mon Sep 17 00:00:00 2001 From: Kharec Date: Tue, 2 Dec 2025 07:35:50 +0100 Subject: [PATCH] revert: remove useless helper as PartOne and PartTwo will have a different behavior --- internal/2025/DayTwo/code.go | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/internal/2025/DayTwo/code.go b/internal/2025/DayTwo/code.go index 51e9bd9..2236dd2 100644 --- a/internal/2025/DayTwo/code.go +++ b/internal/2025/DayTwo/code.go @@ -12,24 +12,6 @@ func init() { registry.Register("2025D2", ParseInput, PartOne, PartTwo) } -func isInvalid(id int, exactTwo bool) bool { - sID := strconv.Itoa(id) - if exactTwo { - half := len(sID) / 2 - return sID[:half] == sID[half:] - } - for patternLength := 1; patternLength <= len(sID)/2; patternLength++ { - repetitions := len(sID) / patternLength - if repetitions < 2 || len(sID)%patternLength != 0 { - continue - } - if strings.Repeat(sID[:patternLength], repetitions) == sID { - return true - } - } - return false -} - func ParseInput(filepath string) []string { content, _ := os.ReadFile(filepath) return strings.Split(strings.TrimSpace(string(content)), "\n") @@ -43,8 +25,12 @@ func PartOne(input []string) int { start, _ := strconv.Atoi(parts[0]) end, _ := strconv.Atoi(parts[1]) for id := start; id <= end; id++ { - if isInvalid(id, true) { - sum += id + sID := strconv.Itoa(id) + if len(sID)%2 == 0 { + half := len(sID) / 2 + if sID[:half] == sID[half:] { + sum += id + } } } }