diff --git a/09dec/main.go b/09dec/main.go new file mode 100644 index 0000000..06c4dfb --- /dev/null +++ b/09dec/main.go @@ -0,0 +1,68 @@ +package main + +import ( + "bufio" + "fmt" + "os" +) + +const ( + GROUP = iota + GARB + IGN +) + +var ( + state int + group int + score int +) + +func main() { + state = GROUP + sc := bufio.NewScanner(os.Stdin) + sc.Split(bufio.ScanRunes) + for sc.Scan() { + parse(sc.Text()) + } + fmt.Println("SCORE:", score) +} + +func parse(c string) { + fmt.Println(c) + if state == IGN { + state = GARB + } else { + switch c { + case ",": + if state == GROUP { + fmt.Println("sep group") + //score += group + } + case "{": + if state == GROUP { + fmt.Println("start group") + group++ + } + case "}": + if state == GROUP { + fmt.Println("end group") + score += group + group-- + } + case "<": + if state == GROUP { + state = GARB + } + case ">": + if state == GARB { + state = GROUP + } + case "!": + if state == GARB { + state = IGN + } + } + } + fmt.Println(state, group, score) +}