Skip to content

Instantly share code, notes, and snippets.

@killme2008
Last active August 29, 2015 14:00
Show Gist options
  • Save killme2008/c5342db9a4a205229c9e to your computer and use it in GitHub Desktop.
Save killme2008/c5342db9a4a205229c9e to your computer and use it in GitHub Desktop.
ThoughtWorks的代码题 https://www.jinshuju.net/f/EGQL3D
;;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 [[x y z] inputs
rs (filter #(zero? (rem n %)) inputs)]
(cond
;;rule 5
(.contains (str n) (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---------")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment