Fork me on GitHub
#babashka
<
2020-03-03
>
borkdude15:03:57

idea: 4clojure as a babashka script, it stores the scores in a local sqlite3 database

borkdude16:03:56

Naive first version:

(ns babashka.4clojure
  (:require [clojure.walk :refer [postwalk]]
            [clojure.edn :as edn]))

(def problems
  {"Intro to Strings"
   {:description "Clojure strings are Java strings. This means that you can use any of the Java string methods on Clojure strings."
    :puzzle '(= __ (.toUpperCase "hello world"))}})

(defn -main []
  (loop [[title puzzle] (rand-nth (seq problems))]
    (loop []
      (println title)
      (println (:description puzzle))
      (prn (:puzzle puzzle))
      (let [answer (edn/read-string (read-line))
            substituted (postwalk #(if (= '__ %) answer %) (:puzzle puzzle))]
        (prn substituted)
        (if (eval substituted)
          (println "Correct!\n")
          (do (println "Incorrect. Try again.")
              (recur)))))
    (recur (rand-nth (seq problems)))))

(-main)

😎 20