Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Params:
- ; a, b, c, d - input sets
- ; state - variable for state saving
- ; elm - single element used in contains subfunction
- (defn megaTask [a b c d &{:keys [state, elm] :or {state 0 elm 0}}]
- (cond
- ;Subfunction contains
- ;Checks if elm is in list a
- ;Non empty list mean true, empty list - false
- (= state 1) (cond
- (empty? a) nil
- (= elm (first a)) '(0)
- true (megaTask (rest a) b c d :state 1 :elm elm)
- )
- ;Subfunction union
- ;Creates union of two sets - a and b
- (= state 2) (cond
- (empty? b) a
- (megaTask a () () () :state 1 :elm (first b)) (megaTask a (rest b) () () :state 2)
- true (cons (first b) (megaTask a (rest b) '() '() :state 2))
- )
- ;Subfunction difference
- ;Computes difference of two sets - a and b
- (= state 3) (cond
- (empty? a) ()
- (megaTask b () () () :state 1 :elm (first a)) (megaTask (rest a) b () () :state 3)
- true (cons (first a) (megaTask (rest a) b '() '() :state 3))
- )
- ;Subfunction intersection
- ;Computes intersection of two sets - a and b
- (= state 4) (cond
- (empty? a) ()
- (megaTask b () () () :state 1 :elm (first a)) (cons (first a) (megaTask (rest a) b () () :state 4))
- true (megaTask (rest a) b () () :state 4)
- )
- ;Computes target result - (A intersects (B union C)) intersects D
- true (megaTask (megaTask (megaTask b c () () :state 2) a () () :state 4) d () () :state 4)
- )
- )
- (print (megaTask '(1 2 3 4 5 6 7) '(2 3 4 5 6) '(7 8 9 10 11 12) '(5 6 7 8 9)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement