Skip to content

Instantly share code, notes, and snippets.

@koganei
Last active August 29, 2015 14:10
Show Gist options
  • Save koganei/b0a782f638f2d02023e3 to your computer and use it in GitHub Desktop.
Save koganei/b0a782f638f2d02023e3 to your computer and use it in GitHub Desktop.
Haskell & Clojure Fizzbuzz
(defn fizz-buzz []
(loop [i 1]
(if (<= i 100)
(do
(if (and (= (rem i 3) 0) (= (rem i 5) 0))
(println "fizzbuzz")
(if (= (rem i 3) 0)
(println "fizz")
(if (= (rem i 5) 0)
(println "buzz")
(println i))))
(recur (inc i))))))
fizz x = x `mod` 3 == 0
buzz x = x `mod` 5 == 0
fizzBuzz = [
if fizz x && buzz x then "fizzbuzz"
else if fizz x then "fizz"
else if buzz x then "buzz"
else show x
|
x <- [1..]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment