Advertisement
Guest User

perms

a guest
Nov 30th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defn perms [bag]
  2.   "Gets all permutations in a bag of items. Assumes they are distinct"
  3.     (lazy-seq
  4.       (if (empty? bag) '(())
  5.         (mapcat (fn [x]
  6.                   (map #(cons x %) (perms (remove #(= x %) bag)))) bag))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement