Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bowling Counting algorithm from InterviewStreet

Tags:

algorithm

I don't know if this is the right section... but here goes:

Last weeks contest on interviewstreet (Code Sprint 3) had a problem called bowling. (10 pin bowling, N frames). The point is to count the number of ways to score M points by playing N frames.

Problem Statement is here: http://pastebin.com/cyeLML8U

I'm pretty sure I've solved the problem using 2 dimensional DP. However, I get the 3rd sample data wrong (1 Frame, 25 points). The sample answer is 1, however I get 6.

This is their explanation of the sample answer:

For the third case, there is only 1 way. Score a strike in the first frame, score another strike with the first extra ball, and an additional 5 with the second extra ball.

However, can't you score a strike in the first (and only) frame, then score any of the following in the subsequent extra frames?

10 5
9 6
8 7
7 8
6 9
5 10

I can't wrap my head around why "1" is the right answer.... I've looked on wikipedia for the rules too.

Their answer is probably right, and I'm probably overlooking something REALLY obvious. Can anyone tell me what's wrong with my answer?

like image 284
dave Avatar asked Dec 03 '25 12:12

dave


2 Answers

You cannot get 9 pins with the first extra ball and then 6 pins with the second extra ball because there is only 1 pin left standing when you bowl the second extra ball.

like image 106
beaker Avatar answered Dec 06 '25 04:12

beaker


But if you don't get a strike on the second ball, you only have the opportunity to "pick up the spare." That is, you only get 10 pins. So if you get a strike on the first ball and then 9 pins on the second ball, the most you can get on the third ball is 1.

like image 31
Jim Mischel Avatar answered Dec 06 '25 04:12

Jim Mischel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!