diff --git a/internal/2017/DayFour/code.go b/internal/2017/DayFour/code.go new file mode 100644 index 0000000..12ecbb9 --- /dev/null +++ b/internal/2017/DayFour/code.go @@ -0,0 +1,40 @@ +package dayfour + +import ( + "advent-of-code/internal/registry" + "os" + "strings" +) + +func init() { + registry.Register("2017D4", ParseInput, PartOne, PartTwo) +} + +func ParseInput(filepath string) []string { + content, _ := os.ReadFile(filepath) + return strings.Split(string(content), "\n") +} + +func PartOne(data []string) int { + validCount := 0 + for _, passphrase := range data { + words := strings.Fields(passphrase) + seen := make(map[string]bool, len(words)) + hasDuplicate := false + for _, word := range words { + if seen[word] { + hasDuplicate = true + break + } + seen[word] = true + } + if !hasDuplicate { + validCount++ + } + } + return validCount +} + +func PartTwo(data []string) int { + return 0 +}