Spoiler - FormatRolls Method - My Solution

This was a nice fun challenge. For me, I found i had to write the most special cases for spares. Also, I’m going to be scoring strikes in my frames in the " " then “X” format.

    public static string FormatRolls (List<int> rolls) {
        string output = "";

        if (rolls.Count > 0) {

            for (int i = 0; i < rolls.Count; i++) {

                if (rolls[i] == 0) {

                    output += "-";

                } else if ((output.Length % 2 != 0 ||                   //If it is an even character
                           output.Length == 20 && rolls[i-2] == 10) &&  //or we are in the bonus rolls
                           rolls[i - 1] != 10 &&                        //and it is not a strike but a
                           rolls[i - 1] + rolls[i] == 10) {             //Spare.

                    output += "/";

                } else if (rolls[i] == 10) { //Strike!

                    if (output.Length < 18) { //If it is not the final frame

                        output += " X";

                    } else {

                        output += "X";
                    }
                } else {

                    output += rolls[i].ToString();
                }
            }
        }
        return output;

Privacy & Terms