Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2017
726
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Oz 1.12 KB | None | 0 0
  1. LIST
  2. attr list
  3. meth init(L)
  4.     list:=L
  5. end
  6. meth isEven(I $)
  7.     local
  8.         fun{Nth L I}
  9.             if I==0 then L.1
  10.             else {Nth L.2 I-1}
  11.             end
  12.         end
  13.     in
  14.         if ({Nth @list I} mod 2)==0 then true
  15.         else false
  16.         end
  17.     end
  18. end
  19. meth get(I $)
  20.     local
  21.         fun{Nth L I}
  22.             if I==0 then L.1
  23.             else {Nth L.2 I-1}
  24.             end
  25.         end
  26.     in
  27.         {Nth @list I}
  28.     end
  29. end
  30. meth getList($)
  31.     @list
  32. end
  33.  
  34. PRODUCER
  35. local
  36.     fun{RandList M}
  37.         if M==0 then nil
  38.         else {OS.rand}|{RandList M-1}
  39.         end
  40.     end
  41.     L
  42. in
  43.     if N==0 then nil
  44.     else L = {New List init({RandList M})}|{Producer M N-1}
  45.     end
  46. end
  47.  
  48. FILTER
  49. case S of nil then nil
  50. [] H|T then
  51.     if {H isEven(J $)} then H|{Filter T J}
  52.     else {Filter T J}
  53.     end
  54. else nil
  55. end
  56.  
  57. CONSUMER
  58. if S1==nil then nil
  59. elseif S2==nil then nil
  60. else
  61.     case S1 of A|B then
  62.         case S2 of C|D then
  63.             if {A get(P $)}>{C get(P $)} then C|A|{Consumer P B D}
  64.             else A|C|{Consumer P B D}
  65.             end
  66.         else nil
  67.         end
  68.     else nil
  69.     end
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement