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
- *)
- let rec megaTask a b c d state elm =
- match state with
- //Subfunction contains
- //Checks if elm is in list a
- //Non empty list mean true, empty list - false
- | 1 -> (if Seq.isEmpty a then
- []
- elif elm = (List.head a) then
- [0]
- else
- (megaTask (List.tail a) b c d 1 elm)
- )
- //Subfunction union
- //Creates union of two sets - a and b
- | 2 -> (if Seq.isEmpty b then
- a
- elif not (Seq.isEmpty (megaTask a [] [] [] 1 (List.head b))) then
- (megaTask a (List.tail b) [] [] 2 0)
- else
- (List.head b) :: (megaTask a (List.tail b) [] [] 2 0))
- //Subfunction union
- //Creates union of two sets - a and b
- | 3 -> (if Seq.isEmpty a then
- []
- elif not (Seq.isEmpty (megaTask b [] [] [] 1 (List.head a))) then
- (megaTask (List.tail a) b [] [] 3 0)
- else
- (List.head a) :: (megaTask (List.tail a) b [] [] 3 0))
- //Subfunction intersection
- //Computes intersection of two sets - a and b
- | 4 -> if Seq.isEmpty a then
- []
- elif not (Seq.isEmpty (megaTask b [] [] [] 1 (List.head a))) then
- (List.head a) :: (megaTask (List.tail a) b [] [] 4 0)
- else
- (megaTask (List.tail a) b [] [] 4 0)
- //Computes target result - (A ∩ (B υ C)) ∩ D
- | _ -> (megaTask (megaTask (megaTask b c [] [] 2 0) a [] [] 4 0) d [] [] 4 0)
- printfn "%A" (megaTask [1; 2; 3; 4; 5; 6; 7] [2; 3; 4; 5; 6] [7; 8; 9; 10; 11; 12] [5; 6; 7; 8; 9] 0 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement