Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Oz 1.08 KB | None | 0 0
  1. fun {Prod M N}
  2.    if M=<N then M|{Prod M+1 N}
  3.    else nil
  4.    end
  5. end
  6. fun {Sieve P}
  7.    local
  8.       fun {Maxo P Acc}
  9.      case P of H|T then
  10.         if H>Acc then {Maxo T H}
  11.         else {Maxo T Acc}
  12.         end
  13.      else Acc
  14.      end
  15.       end
  16.       fun{Divido P K}
  17.      case P of H|T then
  18.         if H==1 then H|{Divido T K}
  19.         elseif H==K orelse H mod K \= 0 then H|{Divido T K}
  20.         else {Divido T K}
  21.         end
  22.      else nil
  23.      end
  24.       end
  25.       fun {Listo P K Max}
  26.      case P of H|T then
  27.         if K=<Max  then {Listo {Divido P K} K+1 Max}
  28.         else P
  29.         end
  30.      else nil
  31.      end
  32.       end
  33.    in
  34.       {Listo P 2 {Maxo P 0}}
  35.    end      
  36. end
  37. fun{NotPrime S1 S2}
  38.     local
  39.         fun{Removo P El}
  40.             case P of H|T then
  41.                 if H==El then {Removo T El}
  42.                 else H|{Removo T El}
  43.                 end
  44.             else nil
  45.             end
  46.         end
  47.         fun{Listo P Q}
  48.             case Q of H|T then
  49.                 {Listo {Removo P H} T}
  50.             else
  51.                 P
  52.             end
  53.         end
  54.     in
  55.         {Listo S1 S2}
  56.     end
  57. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement