private static int score(String line) {
        int score = 0;
        int expected = 0;
        for (int i = 0, loc = 0; i < 10; expected = ++loc, ++i) {
            char c = line.charAt(loc);
            if (c == 'X') {
                score += 10 + sum(line.charAt(loc + 1), line.charAt(loc + 2));
            } else if (Character.isDigit(c)) {
                int ball = sum(c, line.charAt(++loc));
                if (ball == 10) ball += value(line.charAt(loc + 1));
                score += ball;
            } else {
                throw new IllegalStateException("c is invalid: " + c);
            }
        }
        switch (line.charAt(expected - 1)) {
            case 'X': ++expected;
            case '/': ++expected;
            default: if (line.length() != expected) {
                throw new IllegalStateException("too many frames");
            }
        }
        return score;
    }