Created
September 4, 2016 15:05
-
-
Save HerbM/9725f72ddc531acea8dfc560cdec0ca7 to your computer and use it in GitHub Desktop.
4Clojure problem #58 Black box testing: Find type of set, map, vector, list without using built-in typing functions etc.
This file contains hidden or 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
(defn tipe [s] | |
(let [sym1 (gensym) sym2 (gensym) | |
sym3 (gensym) s12 (conj s {sym1 sym2}) | |
s1221 (conj (conj s {sym2 sym1}) s12)] | |
(if (get s12 sym1) :map | |
(if (get s12 {sym1 sym2}) :set | |
(if (= (first s1221) s12) :list :vector))))) | |
(= :map (tipe {:a 1, :b 2})) | |
(= :list (tipe (range (rand-int 20)))) | |
(= :vector (tipe [1 2 3 4 5 6])) | |
(= :set (tipe #{10 (rand-int 5)})) | |
(= [:map :set :vector :list] (map tipe [{} #{} [] ()])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment