Yay! Thanks for the feedback everyone. I originally had it as a 'cond' but because I was using 'println' directly in my fizzy function I was getting on 15 for example "fizzbuzz, buzz, fizz" but changing it to more pure function would probably deal with that. I'll have a play with 'when' as well, hadn't tried that one yet.
Thanks again and I look forward to showing off some Clojure creations in the wild soon. On Saturday, 29 December 2012 22:35:38 UTC+10, Sean Chalmers wrote: > > Greetings all! > > I'm just starting out in the so far wonderful world of Clojure and to help > me get started I had a crack at one of my favourites, the FizzBuzz program. > For anyone that isn't familiar with FizzBuzz, it is designed to count from > 1 to N and take the following actions when certain conditions are met: > > - When the remainder of i divided by 3 is 0 print "Fizz" > - When the remainder of i divided by 5 is 0 print "Buzz" > - When both the former are true of i print "FizzBuzz" > > I crafted the following as a solution and I would really appreciate some > more experienced Clojurians casting their eye over it and letting me know > if what I've done is in the style and spirit of Clojure. Also this is my > first functional language so any feedback on that would be awesome too. :) > > I'm aware it's only a teeeeeeeensy piece of code so not terribly > indicative of the hilarity that might ensue on a larger project but all the > same. Enough of my blathering here is the meaty bit: > > (defn zero-remainder? [x y] > (zero? (rem x y))) > > (defn fizzy [x] > (let [fizz (zero-remainder? x 3) buzz (zero-remainder? x 5)] > (if (and fizz buzz) > (println "FizzBuzz: " x) > (if buzz > (println "Buzz: " x) > (if fizz > (println "Fizz: " x)))))) > > (doseq [x (range 1 25)] > (fizzy x)) > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en
