diff --git a/07dec/input_test b/07dec/input_test new file mode 100644 index 0000000..8a41324 --- /dev/null +++ b/07dec/input_test @@ -0,0 +1,13 @@ +pbga (66) +xhth (57) +ebii (61) +havc (66) +ktlj (57) +fwft (72) -> ktlj, cntj, xhth +qoyq (66) +padx (45) -> pbga, havc, qoyq +tknk (41) -> ugml, padx, fwft +jptl (61) +ugml (68) -> gyxo, ebii, jptl +gyxo (61) +cntj (57) diff --git a/07dec/main.go b/07dec/main.go new file mode 100644 index 0000000..9f995e3 --- /dev/null +++ b/07dec/main.go @@ -0,0 +1,49 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strings" +) + +func main() { + parents := make(map[string]bool) + children := make(map[string]bool) + sc := bufio.NewScanner(os.Stdin) + for sc.Scan() { + s := strings.Split(sc.Text(), " -> ") + parents[parseParent(s[0])] = true + if len(s) > 1 { + for _, c := range parseChildren(s[1]) { + children[c] = true + } + } + } + //fmt.Println(parents) + //fmt.Println(children) + fmt.Println(uniq(parents, children)) +} + +func parseParent(s string) string { + return strings.Split(s, " ")[0] +} + +func parseChildren(s string) []string { + ret := []string{} + for _, c := range strings.Split(s, ", ") { + ret = append(ret, c) + } + return ret +} + +func uniq(p map[string]bool, c map[string]bool) string { + for e := range c { + delete(p, e) + } + fmt.Println(len(p)) + for e := range p { + return e + } + return "not found" +}