Last active
December 10, 2017 03:45
-
-
Save jjhop/aced08715148789455675092f1d68466 to your computer and use it in GitHub Desktop.
This file contains 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
(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