tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -0,0 +1,14 @@
|
|||
(require '[clojure.string :as str])
|
||||
|
||||
(defn guess-game [low high]
|
||||
(printf "Think of a number between %s and %s.\n (use (h)igh (l)ow (c)orrect)\n" low high)
|
||||
(loop [guess (/ (inc (- high low)) 2)
|
||||
[step & more] (next (iterate #(/ % 2) guess))]
|
||||
(printf "I guess %s\n=> " (Math/round (float guess)))
|
||||
(flush)
|
||||
(case (first (str/lower-case (read)))
|
||||
\h (recur (- guess step) more)
|
||||
\l (recur (+ guess step) more)
|
||||
\c (println "Huzzah!")
|
||||
(do (println "Invalid input.")
|
||||
(recur guess step)))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue