From 8e9e37366b9625d71d383592086043e8a4c7f30e Mon Sep 17 00:00:00 2001 From: Kharec Date: Tue, 23 Dec 2025 06:34:47 +0100 Subject: [PATCH] feat: solve part two usinge slices.Sort() to detect anagram --- internal/2017/DayFour/code.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/internal/2017/DayFour/code.go b/internal/2017/DayFour/code.go index 12ecbb9..f36a770 100644 --- a/internal/2017/DayFour/code.go +++ b/internal/2017/DayFour/code.go @@ -3,6 +3,7 @@ package dayfour import ( "advent-of-code/internal/registry" "os" + "slices" "strings" ) @@ -36,5 +37,24 @@ func PartOne(data []string) int { } func PartTwo(data []string) int { - return 0 + validCount := 0 + for _, passphrase := range data { + words := strings.Fields(passphrase) + seen := make(map[string]bool, len(words)) + hasAnagram := false + for _, word := range words { + runes := []rune(word) + slices.Sort(runes) + normalized := string(runes) + if seen[normalized] { + hasAnagram = true + break + } + seen[normalized] = true + } + if !hasAnagram { + validCount++ + } + } + return validCount }