package one import ( "bytes" "slices" "strings" "github.com/onyx-and-iris/aoc2024/day-23/internal/set" ) func Solve(buf []byte) (int, error) { r := bytes.NewReader(buf) connections, err := parseLines(r) if err != nil { return 0, err } networks := make(map[string]*set.Set) for _, connection := range connections { if _, found := networks[connection[0]]; !found { networks[connection[0]] = set.New() } networks[connection[0]].Add(connection[1]) if _, found := networks[connection[1]]; !found { networks[connection[1]] = set.New() } networks[connection[1]].Add(connection[0]) } setIdentifiers := make(map[string]struct{}) for name := range networks { if !strings.HasPrefix(name, "t") { continue } for _, node := range networks[name].List() { for _, node2 := range networks[node].List() { if slices.Contains(networks[node2].List(), name) { s := set.New() s.Add(name) s.Add(node) s.Add(node2) setIdentifiers[s.String()] = struct{}{} } } } } return len(setIdentifiers), nil }