Skip to content

Instantly share code, notes, and snippets.

@jjhop
Last active December 10, 2017 03:45
Show Gist options
  • Save jjhop/aced08715148789455675092f1d68466 to your computer and use it in GitHub Desktop.
Save jjhop/aced08715148789455675092f1d68466 to your computer and use it in GitHub Desktop.
(ns game)
(defn- guess
[current-min current-max n]
(let [mid (int (/ (+ current-min current-max) 2))
res (do
(println (str "Czy twoja liczba to: " mid))
(read-line))]
(cond
(.equals res "<") (guess current-min mid (inc n))
(.equals res ">") (guess mid current-max (inc n))
(.equals res "=") '(:success n)
true '(:exit))))
(defn start
[]
(let [r (guess 0 100 1)
x (nth r 0)]
(cond
(= x :success) (println "Zgadłeś!") ;; (nth r 1)
(= x :exit) (println "Sayonara!"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment