adventofcode/07dec/main.go

50 lines
843 B
Go

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"
}