Module:Shared: Difference between revisions

Added GCD function
(Added custom sort function)
(Added GCD function)
Line 268: Line 268:
     for k, v in pairs(obj) do res[p.clone(k)] = p.clone(v) end
     for k, v in pairs(obj) do res[p.clone(k)] = p.clone(v) end
     return res
     return res
end
-- Euclid's Greatest Common Divisor algorithm
function p.gcd(a, b)
  if(a == b) then
    return a
  else
    if(a > b) then
      if b == 0 then
        return a
      else
        return p.gcd(a - b, b)
      end
    else
      if a == 0 then
        return b
      else
        return p.gcd(a, b - a)
      end
    end
  end
end
end
   
   
return p
return p