Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; #1
- (defn fizzbuzzer [z]
- "fizzbuzz checker."
- (let [fizz? (zero? (rem z 3))
- buzz? (zero? (rem z 5))
- fizzbuzz? (and fizz? buzz?)]
- (cond fizzbuzz? "FizzBuzz"
- buzz? "Buzz"
- fizz? "Fizz"
- :else z)))
- ; #2
- (defn fizzbuzzer2 [z]
- "fizzbuzz checker."
- (let [fb (str
- (if (zero? (rem z 3)) "Fizz" "")
- (if (zero? (rem z 5)) "Buzz" ""))]
- (if (seq fb) fb z)))
- ; profiling ;
- ; (time (fizzbuzzer 1500))
- ; => "Elapsed time: 0.098058 msecs"
- ; (time (fizzbuzzer2 1500))
- ; => "Elapsed time: 0.150438 msecs"
- ;; note: profiling done on separate instances to avoid caching
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement