Advertisement
Guest User

Untitled

a guest
Jul 15th, 2011
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.40 KB | None | 0 0
  1. 11.
  2.  
  3. function IsPrimeNumber(Number)
  4.     local X, Y
  5.     Number = math.floor(Number)
  6.     if (Number < 1) then return(false) end
  7.     for X = 0, (Number - 1), 1 do
  8.         for Y = 0, (Number - 1), 1 do
  9.             if (X * Y == Number) then return(false) end
  10.         end
  11.     end
  12.     return(true)
  13. end
  14. print(IsPrimeNumber(11))
  15.  
  16. 12.
  17.  
  18. function GreatestCommonDivisor(VarA,VarB)
  19.     local Greater, Smaller, I
  20.     local Result = nil
  21.     Greater = math.max(VarA,VarB)
  22.     Smaller = math.min(VarA,VarB)
  23.     for I = 1, Greater, 1 do
  24.         if (Greater % I == 0) and (Smaller % I == 0) then
  25.             Result = I
  26.         end
  27.     end
  28.     return(Result)
  29. end
  30. print(GreatestCommonDivisor(441,84))
  31.  
  32. 13.
  33.  
  34. function Coprime(VarA,VarB)
  35.     local Greater, Smaller, I
  36.     local Result = nil
  37.     Greater = math.max(VarA,VarB)
  38.     Smaller = math.min(VarA,VarB)
  39.     for I = 1, Greater, 1 do
  40.         if (Greater % I == 0) and (Smaller % I == 0) then
  41.             Result = I
  42.         end
  43.     end
  44.     if (Result == 1) then return(true) end
  45.     return(false)
  46. end
  47. print(Coprime(14,15))
  48.  
  49. 18.
  50. function PrimeList(n)
  51.     local I
  52.     local List = {}
  53.     local function IsPrime(Number)
  54.         local X, Y
  55.         Number = math.floor(Number)
  56.         if (Number < 1) then return(false) end
  57.         for X = 0, (Number - 1), 1 do
  58.             for Y = 0, (Number - 1), 1 do
  59.                 if (X * Y == Number) then return(false) end
  60.             end
  61.         end
  62.         return(true)
  63.     end
  64.     for I = 2, n, 1 do
  65.         if IsPrime(I) then table.insert(List,I) end
  66.     end
  67.     return(List)
  68. end
  69. print(table.concat(PrimeList(10)," "))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement