# ibdknox/yellow_belt_clojure_katas forked from gigasquid/yellow_belt_clojure_katas

first pass

`Signed-off-by: Chris Granger <ibdknox@gmail.com>`
1 parent 5fd870f commit 1eb949b08a95e8d41f0dff5460efaf07b5b095c5 committed Apr 16, 2011
12 src/clojure_katas/fib.clj
 @@ -3,7 +3,13 @@ ;; Calculate the fibonacci sequence ;; f(0) = 0, f(1) = 1 ;; f(n) = f(n-1) + f(n-2) - -(defn fib[n]) - +;; +(defn fib-seq + ([] (fib-seq 0 1)) + ([prev cur] + (lazy-seq + (cons prev (fib-seq cur (+ prev cur)))))) + +(defn fib[n] + (nth (fib-seq) n))
9 src/clojure_katas/fizzbuzz.clj
 @@ -5,5 +5,12 @@ ;; and "fizzbuzz" for n divisible by 5 and 3 ;; otherwise just the number -(defn answer [n]) +(defn answer [n] + (let [div3 (zero? (mod n 3)) + div5 (zero? (mod n 5))] + (cond + (and div3 div5) "fizzbuzz" + div3 "fizz" + div5 "buzz" + :else n)))
10 src/clojure_katas/gcd.clj
 @@ -5,5 +5,13 @@ ;; gcd(a,0) = a ;; gcd(b, a mod b) -(defn gcd [a b]) +(defn gcd [a b] + (let [m (min a b)] + (if (= 0 m) + (max a b) + (loop [cur m] + (if (or (= 1 cur) + (and (zero? (mod a cur)) (zero? (mod b cur)))) + cur + (recur (dec cur)))))))
3 src/clojure_katas/nasa_countdown.clj
 @@ -3,5 +3,6 @@ ;; Countdown should return a list counting down from the start all the ;; way to zero -(defn countdown [start]) +(defn countdown [start] + (range start -1 -1))
3 src/clojure_katas/reverseword.clj
 @@ -2,4 +2,5 @@ ;; Reverse a given input word -(defn reverse-word [word]) +(defn reverse-word [word] + (apply str (reverse word)))
8 src/clojure_katas/teaparty.clj
 @@ -7,5 +7,11 @@ ;; A knight is addressed as Sir ;; The return string should be "Hello (the title) (last name) -(defn welcome [last-name is-woman? is-sir?]) +(defn welcome [last-name is-woman? is-sir?] + (let [greeting (cond + (and is-woman? is-sir?) "Lady " + is-sir? "Sir " + is-woman? "Ms. " + :else "Mr. ")] + (str "Welcome " greeting last-name)))
10 src/clojure_katas/teleprompter.clj
 @@ -1,10 +1,16 @@ -(ns clojure-katas.teleprompter) +(ns clojure-katas.teleprompter + (:use [clojure.string :only [split]])) ;; Given an input text string and a list of slang words and their ;; translations ;; return the cleansed input string of the slang words -(defn translate [input-string dictionary]) +(defn translate [input-string dictionary] + (let [parts (split input-string #"\b")] + (reduce str (map #(if-let [replc (get dictionary %)] + replc + %) + parts))))
2 test/clojure_katas/test/fib.clj
 @@ -5,7 +5,7 @@ (deftest fibtest - (future-facts "about the fib function" + (facts "about the fib function" (fib 0) => 0 (fib 1) => 1 (fib 3) => 2
2 test/clojure_katas/test/fizzbuzz.clj
2 test/clojure_katas/test/gcd.clj
 @@ -5,7 +5,7 @@ (deftest gcd-test - (future-facts "about gcd" + (facts "about gcd" (gcd 3 0) => 3 (gcd 48 180) => 12 (gcd 9 28) => 1))
4 test/clojure_katas/test/nasa_countdown.clj
 @@ -5,8 +5,8 @@ (deftest countdown-test - (future-fact (countdown 5) => '(5 4 3 2 1 0)) - (future-fact (countdown 0) => '(0))) + (fact (countdown 5) => '(5 4 3 2 1 0)) + (fact (countdown 0) => '(0)))
2 test/clojure_katas/test/reverseword.clj
 @@ -5,4 +5,4 @@ (deftest reverse-word-test - (future-fact (reverse-word "looc") => "cool")) + (fact (reverse-word "looc") => "cool"))
6 test/clojure_katas/test/teaparty.clj
 @@ -5,7 +5,7 @@ (deftest tea-party-test - (future-fact (welcome "Austen" true false) => "Welcome Ms. Austen") - (future-fact (welcome "Orwell" false false) => "Welcome Mr. Orwell") - (future-fact (welcome "Newton" false true) => "Welcome Sir Newton")) + (fact (welcome "Austen" true false) => "Welcome Ms. Austen") + (fact (welcome "Orwell" false false) => "Welcome Mr. Orwell") + (fact (welcome "Newton" false true) => "Welcome Sir Newton"))
2 test/clojure_katas/test/teleprompter.clj
 @@ -8,7 +8,7 @@ "brainspin" "insomnia"}) (deftest teleprompter-test - (future-facts "about translate" + (facts "about translate" (translate "In the hizzle" dict-1) => "In the house" (translate "In the hizzle, hizzle" dict-1)