Skip to content

Instantly share code, notes, and snippets.

@killme2008
Last active August 29, 2015 14:00

Revisions

  1. killme2008 revised this gist Apr 30, 2014. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions tw_test.clj
    Original file line number Diff line number Diff line change
    @@ -4,12 +4,11 @@
    (Integer/valueOf x))))

    (defn- say-what [inputs words n]
    (let [s (str n)
    [x y z] inputs
    (let [[x y z] inputs
    rs (filter #(zero? (rem n %)) inputs)]
    (cond
    ;;rule 5
    (.contains s (str x)) (get words x)
    (.contains (str n) (str x)) (get words x)
    ;;rule 3,4
    (seq rs) (clojure.string/join (map (partial get words) rs))
    :else n)))
    @@ -23,4 +22,4 @@
    (println "---------Begin of ouput---------")
    (doseq [n (range 1 101)]
    (println (say-what inputs words n)))
    (println "---------End of ouput---------")))
    (println "---------End of ouput---------")))
  2. killme2008 created this gist Apr 30, 2014.
    26 changes: 26 additions & 0 deletions tw_test.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    ;;Code for https://www.jinshuju.net/f/EGQL3D
    (defn- read-n-numbers [n]
    (repeatedly n #(let [x (read-line)]
    (Integer/valueOf x))))

    (defn- say-what [inputs words n]
    (let [s (str n)
    [x y z] inputs
    rs (filter #(zero? (rem n %)) inputs)]
    (cond
    ;;rule 5
    (.contains s (str x)) (get words x)
    ;;rule 3,4
    (seq rs) (clojure.string/join (map (partial get words) rs))
    :else n)))

    (defn- tw-test
    "Thoughtworks test."
    []
    (let [inputs (read-n-numbers 3)
    words (zipmap inputs ["Fizz" "Buzz" "Whizz"])]
    (println "Inputs:" inputs)
    (println "---------Begin of ouput---------")
    (doseq [n (range 1 101)]
    (println (say-what inputs words n)))
    (println "---------End of ouput---------")))