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
