Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns task_1)
- ;; p - prefix to add
- ;; a - list of elements
- ;; n - onumber of elements (count a)
- ;; ex - exclude
- (defn permute_add [p, a, n]
- (if (= n 0)
- nil
- (if (= (nth a (- n 1)) (last p))
- (permute_add p a (- n 1))
- (concat
- (conj (permute_add p a (- n 1))
- (concat p (list (nth a (- n 1)))))))))
- ;; apply permute_add to every item of list
- (defn permute_add_list [list, a, n, counter]
- (if (= counter (count list))
- (if (nil? list)
- (permute_add `() a n)
- nil)
- (concat
- (permute_add (nth list counter) a n)
- (permute_add_list list a n (+ counter 1)))))
- (defn perm_of_len [a, n]
- (if (= n 0)
- nil
- (permute_add_list (perm_of_len a (- n 1)) a (count a) 0)))
- (perm_of_len `(0 1 2 3) 2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement