Day 7: Recursive circus
hmvwl
This commit is contained in:
parent
e112db3506
commit
f8eb4c2896
13
07dec/input_test
Normal file
13
07dec/input_test
Normal file
@ -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)
|
49
07dec/main.go
Normal file
49
07dec/main.go
Normal file
@ -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"
|
||||
}
|
Loading…
Reference in New Issue
Block a user