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