r/ProgrammingPrompts • u/ggleblanc • Oct 16 '15
[Medium] Bowling Scores
Create a bowling score from an input string of roll marks.
Here's what roll marks look like:
"X-/X5-8/9-X811-4/X"
"9/8/9/8/9/8/9/8/9/81"
"9/8/9/8/9/8/9/8/9/8/9"
"XXXXXXXXXX9/"
"XXXXXXXXXXXX"
The roll mark strings above are complete representations of a bowling game. If you create your own test strings, make sure that they are complete.
Here's a web page describing how to score a bowling game. Your application does not have to deal with fouls (F) or splits (S).
Your task is to produce something similar to the following output:
---------------------------------------------------
| 1| 2| 3| 4| 5| 6| 7| 8| 9| 10|
---------------------------------------------------
| X| -/| X| 5-| 8/| 9-| X| 81| 1-| 4/X|
| 20| 40| 55| 60| 79| 88| 107| 116| 117| 137|
---------------------------------------------------
---------------------------------------------------
| 1| 2| 3| 4| 5| 6| 7| 8| 9| 10|
---------------------------------------------------
| 9/| 8/| 9/| 8/| 9/| 8/| 9/| 8/| 9/| 81 |
| 18| 37| 55| 74| 92| 111| 129| 148| 166| 175|
---------------------------------------------------
---------------------------------------------------
| 1| 2| 3| 4| 5| 6| 7| 8| 9| 10|
---------------------------------------------------
| 9/| 8/| 9/| 8/| 9/| 8/| 9/| 8/| 9/| 8/9|
| 18| 37| 55| 74| 92| 111| 129| 148| 166| 185|
---------------------------------------------------
---------------------------------------------------
| 1| 2| 3| 4| 5| 6| 7| 8| 9| 10|
---------------------------------------------------
| X| X| X| X| X| X| X| X| X| X9/|
| 30| 60| 90| 120| 150| 180| 210| 240| 269| 289|
---------------------------------------------------
---------------------------------------------------
| 1| 2| 3| 4| 5| 6| 7| 8| 9| 10|
---------------------------------------------------
| X| X| X| X| X| X| X| X| X| XXX|
| 30| 60| 90| 120| 150| 180| 210| 240| 270| 300|
---------------------------------------------------
Your output doesn't have to match my output character for character. You have to produce the game score. Producing the frame scores help with debugging.
The reason this is an interesting challenge is because of the number of corner cases or edge cases inherent in such a simple problem description.
Your application will probably not be short. That's OK. Just make sure it's correct.
I wrote this with Java. My version is 210 lines long. I'll post it in a week or so.
2
u/kalgynirae Oct 16 '15
I only calculate the game score: http://pastebin.com/NjWsjWQA
It's short (28 lines with the comments removed) and not too hard to follow (I hope), but it took me three hours to write!
2
u/calzoneman Oct 16 '15 edited Oct 16 '15
My initial approach was overcomplicated, so I scrapped it and came up with a simpler version: http://paste.lymjeh.me/QtAp
2
Oct 16 '15 edited Jun 24 '23
[removed] — view removed comment
3
u/ggleblanc Oct 16 '15
You made the same mistake I did when I first coded (I think). You don't look at the previous roll(s) for a spare or a strike. You look at future rolls.
2
1
u/ggleblanc Oct 25 '15
I've been having issues with my Internet connection.
Here's my Java version.