Last active
January 3, 2016 07:19
-
-
Save Janiczek/8429048 to your computer and use it in GitHub Desktop.
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
; I know how to do it manually: | |
(run 5 [q] | |
(let [example-map {:m1 [1 2 3] | |
:m2 [1 4] | |
:m3 [2 1 3]} | |
my-map {:m1 (lvar) | |
:m2 (lvar) | |
:m3 (lvar)}] | |
(all | |
(== q plan) | |
(permuteo (example-map :m1) (my-map :m1)) | |
(permuteo (example-map :m2) (my-map :m2)) | |
(permuteo (example-map :m3) (my-map :m3))))) | |
; => ({:m1 (1 2 3), :m2 (1 4), :m3 (2 1 3)} | |
; {:m1 (1 2 3), :m2 (1 4), :m3 (1 2 3)} | |
; {:m1 (1 2 3), :m2 (1 4), :m3 (2 3 1)} | |
; {:m1 (1 2 3), :m2 (1 4), :m3 (1 3 2)} | |
; {:m1 (1 2 3), :m2 (1 4), :m3 (3 2 1)}) |
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
; But how to do it programatically, for variable number of keys in these maps? | |
(defn contains-permutations-of [q example-map] | |
(let [example-keys (keys example-map) | |
my-map (zipmap example-keys | |
(repeatedly lvar))] | |
(all | |
(== q my-map) | |
(?????? #(permuteo (example-map %) (my-map %)) | |
example-keys)))) | |
(run 5 [q] | |
(contains-permutations-of q {:m1 [5 9] :m2 [1 2 3]})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment