Hi Stu,
Stuart Halloway <stuart.hallo...@gmail.com> writes: > Uncle Bob Martin, a very well-respected OO and agile guy, is learning > Clojure. He has posted an example [1] and asked for feedback from the > Clojure community. I have made my suggestions in code [2] and will be > writing them up shortly. > > Would love to see what other folks on this list have to say. My first version came out rather similar to yours, and then I started thinking about turning the problem on its head and making the concept of "types of rolls" more explicit. I'm still not sure how I feel about this, but the line of thinking led me to code like this: (ns bowling-game (:use clojure.contrib.seq-utils)) (def *roll-types* [{:name "strike" :satisfies #(= (first %) 10) :consumes 3 :advances 1} {:name "spare" :satisfies #(= (apply + (take 2 %)) 10) :consumes 3 :advances 2} {:name "regular (underachieving?)" :satisfies (constantly true) :consumes 2 :advances 2}]) (defn roll-type [rolls] (find-first #((:satisfies %) rolls) *roll-types*)) (defn frames [rolls] (when (seq rolls) (let [{:keys [consumes advances]} (roll-type rolls)] (cons (take consumes rolls) (frames (drop advances rolls)))))) (defn score-game [rolls] (reduce + (map #(reduce + %) (take 10 (group-frames rolls))))) Cheers, Mark -- Mark Triggs <mark.h.tri...@gmail.com> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---