Sha256: 3282ab75c343365cfd3026ba1455ab054e92d27185b8aea735ccaeaca1f3a4d0
Contents?: true
Size: 535 Bytes
Versions: 20
Compression:
Stored size: 535 Bytes
Contents
module EbisuConnection class GreatestCommonDivisor class << self def calc(set) self.new(set).calc end end def initialize(set) @set = set.sort.uniq end def calc n = @set.shift return n if n == 1 || @set.empty? while !@set.empty? m = @set.shift n = gcd_euclid(m, n) end n end def gcd_euclid(m, n) m, n = n, m if m < n while n != 0 work = m % n m = n n = work end m end end end
Version data entries
20 entries across 20 versions & 1 rubygems