Browse files

more readable score-game

  • Loading branch information...
1 parent 3c889b0 commit e8fe8c6f7171fb00be9ca059a24b5c7db9bc7308 @stuarthalloway committed Jul 20, 2009
Showing with 7 additions and 3 deletions.
  1. +6 −2 src/bowling_game.clj
  2. +1 −1 test/test/bowling_game.clj
View
8 src/bowling_game.clj
@@ -27,8 +27,12 @@
(lazy-seq (cons (take (balls-to-score rolls) rolls)
(frames (drop (frame-advance rolls) rolls))))))
-(defn score
+(defn score-frame
+ [frame]
+ (reduce + frame))
+
+(defn score-game
"Score a bowling game, passed as a sequence of rolls."
[rolls]
- (apply + (flatten (take 10 (frames rolls)))))
+ (reduce + (map score-frame (take 10 (frames rolls)))))
View
2 test/test/bowling_game.clj
@@ -26,7 +26,7 @@
))
(deftest test-various-games
- (are [description expected-score game] (= expected-score (score game))
+ (are [description expected-score game] (= expected-score (score-game game))
"gutter game" 0 (repeat 0)
"all ones" 20 (repeat 1)
"one spare" 16 (concat [5 5 3] (repeat 0))

0 comments on commit e8fe8c6

Please sign in to comment.