Skip to content

Instantly share code, notes, and snippets.

@Janiczek
Last active January 3, 2016 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Janiczek/8429048 to your computer and use it in GitHub Desktop.
Save Janiczek/8429048 to your computer and use it in GitHub Desktop.
; 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)})
; 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