Advertisement
Guest User

F# var 12

a guest
Dec 16th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.79 KB | None | 0 0
  1. (*
  2. Params:
  3.    a, b, c, d - input sets
  4.    state - variable for state saving
  5.    elm - single element used in contains subfunction
  6. *)
  7. let rec megaTask a b c d state elm =
  8.     match state with
  9.     //Subfunction contains
  10.     //Checks if elm is in list a
  11.     //Non empty list mean true, empty list - false
  12.     | 1 -> (if Seq.isEmpty a then
  13.                 []
  14.             elif elm = (List.head a) then
  15.                 [0]
  16.             else
  17.                 (megaTask (List.tail a) b c d 1 elm)
  18.             )
  19.     //Subfunction union
  20.     //Creates union of two sets - a and b
  21.     | 2 -> (if Seq.isEmpty b then
  22.                 a
  23.             elif not (Seq.isEmpty (megaTask a [] [] [] 1 (List.head b))) then
  24.                 (megaTask a (List.tail b) [] [] 2 0)
  25.             else
  26.                 (List.head b) :: (megaTask a (List.tail b) [] [] 2 0))
  27.     //Subfunction union
  28.     //Creates union of two sets - a and b
  29.     | 3 -> (if Seq.isEmpty a then
  30.                 []
  31.             elif not (Seq.isEmpty (megaTask b [] [] [] 1 (List.head a))) then
  32.                 (megaTask (List.tail a) b [] [] 3 0)
  33.             else
  34.                 (List.head a) :: (megaTask (List.tail a) b [] [] 3 0))
  35.     //Subfunction intersection
  36.     //Computes intersection of two sets - a and b
  37.     | 4 -> if Seq.isEmpty a then
  38.                 []
  39.             elif not (Seq.isEmpty (megaTask b [] [] [] 1 (List.head a))) then
  40.                 (List.head a) :: (megaTask (List.tail a) b [] [] 4 0)
  41.             else
  42.                 (megaTask (List.tail a) b [] [] 4 0)
  43.     //Computes target result - (A ∩ (B υ C)) ∩ D
  44.     | _ -> (megaTask (megaTask (megaTask b c [] [] 2 0) a [] [] 4 0) d [] [] 4 0)
  45.            
  46.  
  47. 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