Guest User

Untitled

a guest
Apr 23rd, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Oz 2.46 KB | None | 0 0
  1. %Zad.3
  2. declare fun {Producer N}
  3.        if N>0 then {OS.rand}|{Producer N-1}
  4.        else nil
  5.        end
  6.     end
  7.  
  8. declare fun {Consument Ciag}
  9.        local fun {MinMax Min#Max Ciag2}
  10.             case Ciag2
  11.             of X|Xs then if X<Min then {MinMax X#Max Xs}
  12.                  elseif X>Max then {MinMax Min#X Xs}
  13.                  else {MinMax Min#Max Xs}
  14.                  end
  15.             [] nil then Ciag#Min#Max
  16.             end
  17.          end
  18.        in {MinMax Ciag.1#Ciag.1 Ciag.2}
  19.        end
  20.     end
  21.        
  22. declare Ciag
  23. thread  Ciag={Producer 10} end
  24. {Browse thread {Consument Ciag} end}
  25.  
  26.  
  27. %Zad.4
  28. declare fun {Producer N}
  29.        local fun {Aux A N}
  30.             case N of
  31.                1 then A
  32.             [] _ then {Aux N|A N-1}
  33.             end
  34.          end
  35.           in {Aux nil N} end
  36.     end
  37.  
  38. declare fun {Transducer S}
  39.        case S of
  40.           H|T then
  41.           H|{Transducer {Filter T fun {$ X} X mod H\=0 end}}
  42.        [] nil then nil
  43.        end
  44.     end
  45.  
  46. declare proc {Sieve N}
  47.        local S1 S2 in
  48.           thread S1={Producer N} end
  49.           thread S2={Transducer S1} end
  50.           thread {Browse S2} end
  51.        end
  52.     end
  53.  
  54. {Sieve 100}
  55.  
  56.  
  57. %Zad.4
  58. fun {PriProducer N}
  59.    local fun {PriProducer_ M}
  60.         if M<N+2 then M|{PriProducer_ M+1}
  61.         else nil
  62.         end
  63.      end
  64.    in {PriProducer_ 2}
  65.    end
  66. end
  67.  
  68. fun {PriTransducer S}
  69.    case S
  70.    of nil then nil
  71.    [] X|S2 then X|{PriTransducer {List.filter S2 fun {$ E} (E mod X > 0) end}}
  72.    end
  73. end
  74.  
  75. declare
  76. S S1
  77. thread S = {PriProducer 30} end
  78. thread S1 = {PriTransducer S} end
  79. thread {Display S1} end
  80.  
  81.  
  82. %Zad.5
  83. declare fun{ScaleStream S C}
  84.        case S
  85.        of H|Hs then H*C|{ScaleStream Hs C}
  86.        [] nil then nil
  87.        end
  88.     end
  89.  
  90. declare fun{PartialSums S}
  91.        local fun{Pomoc S Prev}
  92.             case S
  93.             of H|Hs then (Prev+H)|{Pomoc Hs Prev+H}
  94.             [] nil then nil
  95.             end
  96.          end
  97.        in {Pomoc S 0.} end
  98.     end
  99. {Browse {ScaleStream [1. 4.5 3.5 3.3 2.65] 3.01}}
  100. {Browse {PartialSums [1. 4.5 3.5 3. 2.65]}}
  101.  
  102. %Zad.6
  103. declare
  104. fun {PiProducer N}
  105.    local fun {PiProd_ Mult Sgn N}
  106.         if N>0 then Sgn*1./Mult|{PiProd_ Mult+2. ~1.*Sgn N-1}
  107.         else nil
  108.         end
  109.      end
  110.    in
  111.       {PiProd_ 1. 1. N}
  112.    end
  113. end
  114.  
  115. fun {EulerNumber S S1}
  116.    S1 - (S1-S)*(S1-S) / (S1 - 2.*S + S1)
  117. end
  118.  
  119. fun {EulerTransform S}
  120.    case S
  121.    of nil then nil
  122.    [] X|X2|S2 then {EulerNumber X X2}|{EulerTransform X2|S2}
  123.    [] _ then nil
  124.    end
  125. end
  126.  
  127. declare
  128. S S1 S2 S3
  129. thread S = {PiProducer 15} end
  130. thread S1 = {PartialSums S} end
  131. thread S2 = {ScaleStream S1 4.} end
  132. thread S3 = {EulerTransform S2} end
  133. thread {Display S3} end
Add Comment
Please, Sign In to add comment