June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,9 +1 @@
(defn fizzbuzz [start finish]
(map (fn [n]
(cond
(zero? (mod n 15)) "FizzBuzz"
(zero? (mod n 3)) "Fizz"
(zero? (mod n 5)) "Buzz"
:else n))
(range start finish)))
(fizzbuzz 1 100)
(doseq [x (range 1 101)] (println x (str (when (zero? (mod x 3)) "fizz") (when (zero? (mod x 5)) "buzz"))))

View file

@ -1,4 +1,2 @@
(take 100
(map #(if (pos? (compare %1 %2)) %1 %2)
(map str (drop 1 (range)))
(map str (cycle ["" "" "Fizz"]) (cycle ["" "" "" "" "Buzz"]))))
(let [n nil fizz (cycle [n n "fizz"]) buzz (cycle [n n n n "buzz"]) nums (iterate inc 1)]
(take 20 (map #(if (or %1 %2) (str %1 %2) %3) fizz buzz nums)))

View file

@ -1,19 +1,4 @@
;;Using clojure maps
(defn fizzbuzz
[n]
(let [rule {3 "Fizz"
5 "Buzz"}
divs (->> rule
(map first)
sort
(filter (comp (partial = 0)
(partial rem n))))]
(if (empty? divs)
(str n)
(->> divs
(map rule)
(apply str)))))
(defn allfizzbuzz
[max]
(map fizzbuzz (range 1 (inc max))))
(take 100
(map #(if (pos? (compare %1 %2)) %1 %2)
(map str (drop 1 (range)))
(map str (cycle ["" "" "Fizz"]) (cycle ["" "" "" "" "Buzz"]))))

View file

@ -1,6 +1,19 @@
(take 100
(map #(str %1 %2 (if-not (or %1 %2) %3))
(cycle [nil nil "Fizz"])
(cycle [nil nil nil nil "Buzz"])
(rest (range))
))
;;Using clojure maps
(defn fizzbuzz
[n]
(let [rule {3 "Fizz"
5 "Buzz"}
divs (->> rule
(map first)
sort
(filter (comp (partial = 0)
(partial rem n))))]
(if (empty? divs)
(str n)
(->> divs
(map rule)
(apply str)))))
(defn allfizzbuzz
[max]
(map fizzbuzz (range 1 (inc max))))

View file

@ -1,18 +1,6 @@
(take 100
(
(fn [& fbspec]
(let [
fbseq #(->> (repeat nil) (cons %2) (take %1) reverse cycle)
strfn #(apply str (if (every? nil? (rest %&)) (first %&)) (rest %&))
]
(->>
fbspec
(partition 2)
(map #(apply fbseq %))
(apply map strfn (rest (range)))
) ;;endthread
) ;;endlet
) ;;endfn
3 "Fizz" 5 "Buzz" 7 "Bazz"
) ;;endfn apply
) ;;endtake
(map #(str %1 %2 (if-not (or %1 %2) %3))
(cycle [nil nil "Fizz"])
(cycle [nil nil nil nil "Buzz"])
(rest (range))
))

View file

@ -0,0 +1,18 @@
(take 100
(
(fn [& fbspec]
(let [
fbseq #(->> (repeat nil) (cons %2) (take %1) reverse cycle)
strfn #(apply str (if (every? nil? (rest %&)) (first %&)) (rest %&))
]
(->>
fbspec
(partition 2)
(map #(apply fbseq %))
(apply map strfn (rest (range)))
) ;;endthread
) ;;endlet
) ;;endfn
3 "Fizz" 5 "Buzz" 7 "Bazz"
) ;;endfn apply
) ;;endtake

View file

@ -1,5 +1,9 @@
(map (fn [x] (cond (zero? (mod x 15)) "FizzBuzz"
(zero? (mod x 5)) "Buzz"
(zero? (mod x 3)) "Fizz"
:else x))
(range 1 101))
(defn fizzbuzz [start finish]
(map (fn [n]
(cond
(zero? (mod n 15)) "FizzBuzz"
(zero? (mod n 3)) "Fizz"
(zero? (mod n 5)) "Buzz"
:else n))
(range start finish)))
(fizzbuzz 1 100)

View file

@ -1 +1,5 @@
(map #(let [s (str (if (zero? (mod % 3)) "Fizz") (if (zero? (mod % 5)) "Buzz"))] (if (empty? s) % s)) (range 1 101))
(map (fn [x] (cond (zero? (mod x 15)) "FizzBuzz"
(zero? (mod x 5)) "Buzz"
(zero? (mod x 3)) "Fizz"
:else x))
(range 1 101))

View file

@ -1,6 +1 @@
(def fizzbuzz (map
#(cond (zero? (mod % 15)) "FizzBuzz"
(zero? (mod % 5)) "Buzz"
(zero? (mod % 3)) "Fizz"
:else %)
(iterate inc 1)))
(map #(let [s (str (if (zero? (mod % 3)) "Fizz") (if (zero? (mod % 5)) "Buzz"))] (if (empty? s) % s)) (range 1 101))

View file

@ -1,13 +1,6 @@
(defn fizz-buzz
([] (fizz-buzz (range 1 101)))
([lst]
(letfn [(fizz? [n] (zero? (mod n 3)))
(buzz? [n] (zero? (mod n 5)))]
(let [f "Fizz"
b "Buzz"
items (map (fn [n]
(cond (and (fizz? n) (buzz? n)) (str f b)
(fizz? n) f
(buzz? n) b
:else n))
lst)] items))))
(def fizzbuzz (map
#(cond (zero? (mod % 15)) "FizzBuzz"
(zero? (mod % 5)) "Buzz"
(zero? (mod % 3)) "Fizz"
:else %)
(iterate inc 1)))

View file

@ -1,6 +1,13 @@
(map (fn [n]
(if-let [fb (seq (concat (when (zero? (mod n 3)) "Fizz")
(when (zero? (mod n 5)) "Buzz")))]
(apply str fb)
n))
(range 1 101))
(defn fizz-buzz
([] (fizz-buzz (range 1 101)))
([lst]
(letfn [(fizz? [n] (zero? (mod n 3)))
(buzz? [n] (zero? (mod n 5)))]
(let [f "Fizz"
b "Buzz"
items (map (fn [n]
(cond (and (fizz? n) (buzz? n)) (str f b)
(fizz? n) f
(buzz? n) b
:else n))
lst)] items))))

View file

@ -1,4 +1,6 @@
(take 100 (map #(let [s (str %2 %3) ] (if (seq s) s (inc %)) )
(range)
(cycle [ "" "" "Fizz" ])
(cycle [ "" "" "" "" "Buzz" ])))
(map (fn [n]
(if-let [fb (seq (concat (when (zero? (mod n 3)) "Fizz")
(when (zero? (mod n 5)) "Buzz")))]
(apply str fb)
n))
(range 1 101))

View file

@ -1 +1,4 @@
(map #(nth (conj (cycle [% % "Fizz" % "Buzz" "Fizz" % % "Fizz" "Buzz" % "Fizz" % % "FizzBuzz"]) %) %) (range 1 101))
(take 100 (map #(let [s (str %2 %3) ] (if (seq s) s (inc %)) )
(range)
(cycle [ "" "" "Fizz" ])
(cycle [ "" "" "" "" "Buzz" ])))

View file

@ -1,2 +1 @@
(let [n nil fizz (cycle [n n "fizz"]) buzz (cycle [n n n n "buzz"]) nums (iterate inc 1)]
(take 20 (map #(if (or %1 %2) (str %1 %2) %3) fizz buzz nums)))
(map #(nth (conj (cycle [% % "Fizz" % "Buzz" "Fizz" % % "Fizz" "Buzz" % "Fizz" % % "FizzBuzz"]) %) %) (range 1 101))