score =: verb define
if. y. =. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 do. 0
elsif. y. -. 9 0 8 1 7 2 6 3 5 4 4 5 3 6 2 7 8 1 0 9 do. 90
elsif. y. -. 9 1 8 2 7 3 6 4 5 5 4 6 3 7 2 8 1 9 8 2 1 do. 251
elsif. y. -. 10 10 10 10 10 10 10 10 10 10 10 10 do. 300
elsif. y. -. 9 1 10 8 2 10 7 3 10 6 4 10 5 5 10 4 6 10 do. 200
elsif. 1 do. _.
end.
)

NB. all this shows is that the devil is in the tests. As I (and you, I'm
sure) have been following in the Agile groups, the Bowling Game has been
getting a lot of e-ink.

I'm thinking some sort of "scan" test will cover more ground.

assert. (10#0) -. score\ empty_case
assert. (....) -. score\ open_case
NB. I wish J left some of a. free for meta statements
...

-----------------------------------------------------------------------
|\/| Randy A MacDonald             | you can't pay for it,
|/\| [EMAIL PROTECTED]            |       even if you want to.
BSc(Math) UNBF'83 Sapere Aude      | APL: If you can say it, it's done..
Natural Born APL'er                | Demo website: http://142.166.105.166/
----------------------------------------------------(INTP)----{ gnat }-

----- Original Message ----- 
From: "June Kim" <[EMAIL PROTECTED]>
To: "Programming forum" <[email protected]>
Sent: Saturday, March 25, 2006 8:12 AM
Subject: [Jprogramming] Bowling Game Scoring


This is a famous toy problem among many programming languages (ruby,
smalltalk, C#, python, and etc -- google for "bowling kata"), but I
haven't seen a J solution yet. And, I have to admit that I am very
curious how J experts would approach this. ;)

For a very different solution, have a look at Ward Cunningham's regex
version at http://c2.com/doc/bowl/index.html and for a deep and wide
exploration into the scoring code and its design, visit Ron Jeffries
at http://www.xprogramming.com/index.htm

Those who don't know much about bowling, please refer to
http://en.wikipedia.org/wiki/Bowling#Basic_Rules

Following are the test cases for scoring(copied and edited from
http://bossavit.com/cgi-bin/dojo.pl?BowlingGameKata).

empty_case=:0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
open_case=:9 0 8 1 7 2 6 3 5 4 4 5 3 6 2 7 8 1 0 9
spare_case=:9 1 8 2 7 3 6 4 5 5 4 6 3 7 2 8 1 9 8 2 1
strike_case=:10 10 10 10 10 10 10 10 10 10 10 10
alt_case=:9 1 10 8 2 10 7 3 10 6 4 10 5 5 10 4 6 10

assert 0 = score empty_case
assert 90 = score open_case
assert 251 = score spare_case
assert 300 = score strike_case
assert 200 = score alt_case

Could you come up with the verb "score"?

p.s. a variation is scoring as each roll arrives(think of the
electronic score board that's updated automatically just-in-time).
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to