Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %3
- declare
- fun {Random N} if N>0 then {OS.rand}|{Random N-1} else nil end end
- declare
- fun {MinMax S}
- local
- fun {Pom S Min Max}
- case S
- of X|S2 then local Min1=if X<Min then X else Min end Max1=if X>Max then X else Max end in
- (Min1#Max1)|{Pom S2 Min1 Max1} end
- [] nil then nil
- end
- end
- in {Pom S S.1 S.1}
- end
- end
- declare S1 S2
- thread S1={Random 10} end
- thread S2={MinMax S1} end
- thread {Display S2} end
- declare
- proc {Display S}
- case S
- of X|S2 then {Browse X}{Display S2}
- [] nil then skip
- end
- end
- %4
- declare
- fun {Integers N}
- local
- fun {Pom N K}
- if N>=2 then K|{Pom N-1 K+1}
- else nil
- end
- end
- in {Pom N 2}
- end
- end
- declare
- fun {Sieve S}
- case S
- of P|S2 then P|{Sieve {Filter S2 fun {$ X} X mod P \= 0 end}}
- [] nil then nil
- end
- end
- declare S1 S2
- thread S1={Integers 100} end
- thread S2={Sieve S1} end
- thread {Display S2} end
- %5a
- declare
- fun {ScaleStream S C}
- case S
- of X|S2 then (X*C)|{ScaleStream S2 C}
- [] nil then nil
- end
- end
- %5b
- declare
- fun {PartialSums S}
- local
- fun {Sum S Acc}
- case S
- of X|S2 then (Acc+X)|{Sum S2 Acc+X}
- [] nil then nil
- end
- end
- in {Sum S 0.}
- end
- end
- %6a
- declare
- fun {Inverse N}
- local
- fun {Pom N X}
- if N>0 then {Pow ~1. (X-1.)/2.}*(1./X)|{Pom N-1 X+2.}
- else nil
- end
- end
- in {Pom N 1.}
- end
- end
- declare S1 S2 S3
- thread S1={Inverse 10} end
- thread S2={PartialSums S1} end
- thread S3={ScaleStream S2 4.} end
- thread {Display S3} end
- %6b
- declare
- fun {EulerTransform S}
- local
- fun {Pom S S1 S2}
- case S
- of X|Sr then (X-(X-S1)*(X-S1)/(S2-2.*S1+X))|{Pom Sr X S1}
- [] nil then nil
- end
- end
- in {Pom S 0. 0.}
- end
- end
- declare S1 S2 S3 S4
- thread S1={Inverse 10} end
- thread S2={PartialSums S1} end
- thread S3={ScaleStream S2 4.} end
- thread S4={EulerTransform S3} end
- thread {Display S4} end
Add Comment
Please, Sign In to add comment