Created
October 10, 2018 04:51
-
-
Save bobbicodes/2b0d6ae442df23a7002435a696ff06c8 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 ctrain.core | |
(:require [clojure.string :as s] | |
[clojure.set :refer :all]) | |
(:gen-class)) | |
(def problems (read-string (slurp "problems.edn"))) | |
(defn print-prob [n] | |
(println (str "\n#" n ": " (:title (nth problems (dec n))))) | |
(println (str "\n" (:description (nth problems (dec n))) "\n")) | |
(run! println (:tests (nth problems (dec n))))) | |
(defn ans [n] | |
(print-prob n) | |
(read-string (s/replace (:tests (nth problems (dec n))) "__" (read-line)))) | |
(defn evaluate [tests] | |
(loop [tests tests results []] | |
(if (empty? tests) | |
results | |
(recur | |
(rest tests) | |
(conj results | |
(try | |
(eval (read-string (first tests))) | |
(catch Exception e | |
false))))))) | |
(defn -main [] | |
(loop [n 1] | |
(if (every? true? (evaluate (ans n))) | |
(recur (inc n)) | |
(recur n)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment