Last active
November 15, 2016 06:01
-
-
Save kencoba/5edd0af0fba436fb65caa5032a205268 to your computer and use it in GitHub Desktop.
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
(ns tt.core) | |
(def *min-level* 2) | |
(def *chars* "fjdksla;vmc,x.z/rueiwoqpghbnty4738291056:\\@-][^!\"#$%&'()=~|`{+*}<>?_") | |
(def *vals* (to-array (seq *chars*))) | |
(defn interval [] | |
(let [start-time (System/currentTimeMillis)] | |
(fn [] | |
(let [end-time (System/currentTimeMillis)] | |
(- end-time start-time))))) | |
(defn word [level] | |
(clojure.string/join | |
(map #(aget *vals* %1) | |
(for [x (range 0 5)] | |
(int (* (Math/random) level)))))) | |
(defn problem-line [level] | |
(clojure.string/join " " | |
(for [x (range 0 8)] | |
(word level)))) | |
(defn difference [problem-line enter-line] | |
(clojure.string/join | |
(map #(if (= (get %1 0) | |
(get %1 1)) | |
" " | |
(get %1 0)) | |
(map vector | |
problem-line | |
(str enter-line (repeat (- (count problem-line) (count enter-line)) " ")))))) | |
(defn count-wrong [diff-line] | |
(- (count diff-line) | |
((frequencies diff-line) \space))) | |
(defn -main | |
[& args] | |
(loop [level 2] | |
(println "level" level) | |
(let [problem-line (problem-line level)] | |
(println problem-line) | |
(let [inter (interval) | |
enter-line (read-line)] | |
(let [diff-line (difference problem-line enter-line)] | |
(println diff-line) | |
(let [wrongs (count-wrong diff-line)] | |
(if (empty? enter-line) | |
nil | |
(if (and (< wrongs 2) | |
(<= (inter) 20000)) | |
(recur (inc level)) | |
(recur level))))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment