Guest User

Untitled

a guest
Apr 20th, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Oz 1.94 KB | None | 0 0
  1. %3
  2. declare
  3. fun {Random N} if N>0 then {OS.rand}|{Random N-1} else nil end end
  4.  
  5. declare
  6. fun {MinMax S}
  7.    local
  8.       fun {Pom S Min Max}
  9.      case S
  10.      of X|S2 then local Min1=if X<Min then X else Min end Max1=if X>Max then X else Max end in
  11.         (Min1#Max1)|{Pom S2 Min1 Max1} end
  12.      [] nil then nil
  13.      end
  14.       end
  15.    in {Pom S S.1 S.1}
  16.    end
  17. end
  18.  
  19. declare S1 S2
  20. thread S1={Random 10} end
  21. thread S2={MinMax S1} end
  22. thread {Display S2} end
  23.  
  24. declare
  25. proc {Display S}
  26.    case S
  27.    of X|S2 then {Browse X}{Display S2}
  28.    [] nil then skip
  29.    end
  30. end
  31.  
  32. %4
  33. declare
  34. fun {Integers N}
  35.    local
  36.       fun {Pom N K}
  37.      if N>=2 then K|{Pom N-1 K+1}
  38.      else nil
  39.      end
  40.       end
  41.    in {Pom N 2}
  42.    end
  43. end
  44.  
  45. declare
  46. fun {Sieve S}
  47.    case S
  48.    of P|S2 then P|{Sieve {Filter S2 fun {$ X} X mod P \= 0 end}}
  49.    [] nil then nil
  50.    end
  51. end
  52.  
  53. declare S1 S2
  54. thread S1={Integers 100} end
  55. thread S2={Sieve S1} end
  56. thread {Display S2} end
  57.  
  58. %5a
  59. declare
  60. fun {ScaleStream S C}
  61.    case S
  62.    of X|S2 then (X*C)|{ScaleStream S2 C}
  63.    [] nil then nil
  64.    end
  65. end
  66.  
  67. %5b
  68. declare
  69. fun {PartialSums S}
  70.    local
  71.       fun {Sum S Acc}
  72.      case S
  73.      of X|S2 then (Acc+X)|{Sum S2 Acc+X}
  74.      [] nil then nil
  75.      end
  76.       end
  77.    in {Sum S 0.}
  78.    end
  79. end
  80.  
  81. %6a
  82. declare
  83. fun {Inverse N}
  84.    local
  85.       fun {Pom N X}
  86.      if N>0 then {Pow ~1. (X-1.)/2.}*(1./X)|{Pom N-1 X+2.}
  87.      else nil
  88.      end
  89.       end
  90.    in {Pom N 1.}
  91.    end
  92. end
  93.  
  94. declare S1 S2 S3
  95. thread S1={Inverse 10} end
  96. thread S2={PartialSums S1} end
  97. thread S3={ScaleStream S2 4.} end
  98. thread {Display S3} end
  99.  
  100. %6b
  101. declare
  102. fun {EulerTransform S}
  103.    local
  104.       fun {Pom S S1 S2}
  105.      case S
  106.      of X|Sr then (X-(X-S1)*(X-S1)/(S2-2.*S1+X))|{Pom Sr X S1}
  107.      [] nil then nil
  108.      end
  109.       end
  110.    in {Pom S 0. 0.}
  111.    end
  112. end
  113.  
  114. declare S1 S2 S3 S4
  115. thread S1={Inverse 10} end
  116. thread S2={PartialSums S1} end
  117. thread S3={ScaleStream S2 4.} end
  118. thread S4={EulerTransform S3} end
  119. thread {Display S4} end
Add Comment
Please, Sign In to add comment