Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@n2o
Created June 21, 2018 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n2o/92ad8c62d64051f3f50771b67042927e to your computer and use it in GitHub Desktop.
Save n2o/92ad8c62d64051f3f50771b67042927e to your computer and use it in GitHub Desktop.

Clojure Meetup Juni 2018

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment