Last active
September 3, 2020 11:20
-
-
Save sogaiu/41c5de864e2af77ef3dfb520e4e4707f to your computer and use it in GitHub Desktop.
generating strings of radix numbers for clojure
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
(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