Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %Zad.3
- declare fun {Producer N}
- if N>0 then {OS.rand}|{Producer N-1}
- else nil
- end
- end
- declare fun {Consument Ciag}
- local fun {MinMax Min#Max Ciag2}
- case Ciag2
- of X|Xs then if X<Min then {MinMax X#Max Xs}
- elseif X>Max then {MinMax Min#X Xs}
- else {MinMax Min#Max Xs}
- end
- [] nil then Ciag#Min#Max
- end
- end
- in {MinMax Ciag.1#Ciag.1 Ciag.2}
- end
- end
- declare Ciag
- thread Ciag={Producer 10} end
- {Browse thread {Consument Ciag} end}
- %Zad.4
- declare fun {Producer N}
- local fun {Aux A N}
- case N of
- 1 then A
- [] _ then {Aux N|A N-1}
- end
- end
- in {Aux nil N} end
- end
- declare fun {Transducer S}
- case S of
- H|T then
- H|{Transducer {Filter T fun {$ X} X mod H\=0 end}}
- [] nil then nil
- end
- end
- declare proc {Sieve N}
- local S1 S2 in
- thread S1={Producer N} end
- thread S2={Transducer S1} end
- thread {Browse S2} end
- end
- end
- {Sieve 100}
- %Zad.4
- fun {PriProducer N}
- local fun {PriProducer_ M}
- if M<N+2 then M|{PriProducer_ M+1}
- else nil
- end
- end
- in {PriProducer_ 2}
- end
- end
- fun {PriTransducer S}
- case S
- of nil then nil
- [] X|S2 then X|{PriTransducer {List.filter S2 fun {$ E} (E mod X > 0) end}}
- end
- end
- declare
- S S1
- thread S = {PriProducer 30} end
- thread S1 = {PriTransducer S} end
- thread {Display S1} end
- %Zad.5
- declare fun{ScaleStream S C}
- case S
- of H|Hs then H*C|{ScaleStream Hs C}
- [] nil then nil
- end
- end
- declare fun{PartialSums S}
- local fun{Pomoc S Prev}
- case S
- of H|Hs then (Prev+H)|{Pomoc Hs Prev+H}
- [] nil then nil
- end
- end
- in {Pomoc S 0.} end
- end
- {Browse {ScaleStream [1. 4.5 3.5 3.3 2.65] 3.01}}
- {Browse {PartialSums [1. 4.5 3.5 3. 2.65]}}
- %Zad.6
- declare
- fun {PiProducer N}
- local fun {PiProd_ Mult Sgn N}
- if N>0 then Sgn*1./Mult|{PiProd_ Mult+2. ~1.*Sgn N-1}
- else nil
- end
- end
- in
- {PiProd_ 1. 1. N}
- end
- end
- fun {EulerNumber S S1}
- S1 - (S1-S)*(S1-S) / (S1 - 2.*S + S1)
- end
- fun {EulerTransform S}
- case S
- of nil then nil
- [] X|X2|S2 then {EulerNumber X X2}|{EulerTransform X2|S2}
- [] _ then nil
- end
- end
- declare
- S S1 S2 S3
- thread S = {PiProducer 15} end
- thread S1 = {PartialSums S} end
- thread S2 = {ScaleStream S1 4.} end
- thread S3 = {EulerTransform S2} end
- thread {Display S3} end
Add Comment
Please, Sign In to add comment