about | help | code help+videos | done | prefs |
Write a method that accepts a string of 10 1's and 0's. The 1's indicate that a pin remains, while the 0's indicate that a pin has been knocked down. Each character in the string corresponds to the location of a bowling pin. The pins are numbered from 1 to 10 with the first character representing pin 1 which is the pin closest to the bowler. Each row of pins has one more pin than the row before it, so row two contains two pins numbered 2 and 3. Row three contains three pins numbered 4, 5, and 6. The last row has pins numbered 7, 8, 9, and 10. The pin numbers correspond to the character number in the string starting with pin number 1. Note that pins 7 and 10 are in the opposite back corners of the pin configuration. If you bowl and leave only these two pins it is called a bad split. If you knock down all the pins on the first try, it is called a strike (which is a good thing!). Your goal is to translate the string of 1's and 0's in two three possible statements: "Strike!" if no pins remain standing. "bad split." if only pins 7 and 10 remain standing. "go for the spare, # remaining." in all other cases, where # is replaced by the number of pins that remain standing. A spare is when you knock down all the remaining pins on your second shot. While it is possible to do this when you have a bad split, it is very difficult indeed! splitPins("0010101011") → "go for the spare, 5 remaining." splitPins("0000000000") → "Strike!" splitPins("0000000101") → "go for the spare, 2 remaining." ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 290
Copyright Nick Parlante 2017 - privacy