Fork me on GitHub

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


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 (rand-nth (seq problems)))))


😎 20