Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LIST
- attr list
- meth init(L)
- list:=L
- end
- meth isEven(I $)
- local
- fun{Nth L I}
- if I==0 then L.1
- else {Nth L.2 I-1}
- end
- end
- in
- if ({Nth @list I} mod 2)==0 then true
- else false
- end
- end
- end
- meth get(I $)
- local
- fun{Nth L I}
- if I==0 then L.1
- else {Nth L.2 I-1}
- end
- end
- in
- {Nth @list I}
- end
- end
- meth getList($)
- @list
- end
- PRODUCER
- local
- fun{RandList M}
- if M==0 then nil
- else {OS.rand}|{RandList M-1}
- end
- end
- L
- in
- if N==0 then nil
- else L = {New List init({RandList M})}|{Producer M N-1}
- end
- end
- FILTER
- case S of nil then nil
- [] H|T then
- if {H isEven(J $)} then H|{Filter T J}
- else {Filter T J}
- end
- else nil
- end
- CONSUMER
- if S1==nil then nil
- elseif S2==nil then nil
- else
- case S1 of A|B then
- case S2 of C|D then
- if {A get(P $)}>{C get(P $)} then C|A|{Consumer P B D}
- else A|C|{Consumer P B D}
- end
- else nil
- end
- else nil
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement