Advertisement
Guest User

Untitled

a guest
May 24th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. ; #1
  2. (defn fizzbuzzer [z]
  3. "fizzbuzz checker."
  4. (let [fizz? (zero? (rem z 3))
  5. buzz? (zero? (rem z 5))
  6. fizzbuzz? (and fizz? buzz?)]
  7.  
  8. (cond fizzbuzz? "FizzBuzz"
  9. buzz? "Buzz"
  10. fizz? "Fizz"
  11. :else z)))
  12.  
  13. ; #2
  14. (defn fizzbuzzer2 [z]
  15. "fizzbuzz checker."
  16. (let [fb (str
  17. (if (zero? (rem z 3)) "Fizz" "")
  18. (if (zero? (rem z 5)) "Buzz" ""))]
  19. (if (seq fb) fb z)))
  20.  
  21. ; profiling ;
  22. ; (time (fizzbuzzer 1500))
  23. ; => "Elapsed time: 0.098058 msecs"
  24. ; (time (fizzbuzzer2 1500))
  25. ; => "Elapsed time: 0.150438 msecs"
  26.  
  27. ;; note: profiling done on separate instances to avoid caching
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement