Wir haben ein wenig in der REPL gespielt und dabei ist dieser Code entstanden:
(ns intro.core)
(defn spielregeln
"I don't do a whole lot."
[x]
(println x "Hello, World!"))
(+ 1 2)
(def x {:foo "foo"})
:foo
;; FIZZ wenn Eingabe % 3 == 0
;; BUZZ wenn Eingabe % 5 == 0
;; FIZZBUZZ wenn Eingabe % 15 == 0
(defn teilbar? [a b]
(zero? (mod a b)))
(defn spielregeln [eingabe]
(cond
(teilbar? eingabe 15) "FIZZBUZZ"
(teilbar? eingabe 5) "BUZZ"
(teilbar? eingabe 3) "FIZZ"
:else eingabe))
(map spielregeln (range 1 30))
;; Unendliche Lösung mit FizzBuzz
(def nat (iterate inc 1))
(def fizz (cycle ["" "" "FIZZ"]))
(def buzz (cycle ["" "" "" "" "BUZZ"]))
(def fizzbuzz
(map
(fn [n f b] (if (= "" f b) n (str f b)))
nat fizz buzz))
(take 30 fizzbuzz)