Skip to content

Instantly share code, notes, and snippets.

@sogaiu
Last active September 3, 2020 11:20
Show Gist options
  • Save sogaiu/41c5de864e2af77ef3dfb520e4e4707f to your computer and use it in GitHub Desktop.
Save sogaiu/41c5de864e2af77ef3dfb520e4e4707f to your computer and use it in GitHub Desktop.
generating strings of radix numbers for clojure
(require '[clojure.string :as cs])
(require '[clojure.test.check.generators :as gen])
(take 20 (gen/sample-seq
(gen/let [sign (gen/elements ["" "+" "-"])
radix (gen/choose 2 36)
r-or-R (gen/elements ["R" "r"])
n gen/nat
nums (gen/vector (gen/choose 0 (dec radix))
(inc n))
caps (gen/vector gen/boolean
(inc n))]
(str sign
radix
r-or-R
(cs/join (map (fn [num cap]
(if (<= num 9)
(char (+ num 48))
(char (+ num (if cap 55 87)))))
nums
caps))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment