Last active
August 29, 2015 14:00
-
-
Save killme2008/c5342db9a4a205229c9e to your computer and use it in GitHub Desktop.
ThoughtWorks的代码题 https://www.jinshuju.net/f/EGQL3D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;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