summaryrefslogtreecommitdiff
path: root/gcd.rb
blob: 1fd7d9f2b2208ec184223fb31f95992abb6875e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/env ruby

def gcd2 a, b
    if b == 0
        a
    else
        gcd2 b, a % b
    end
end

def gcdn ns
    ns.reduce{ |a, b| gcd2 a, b }
end

puts gcdn ARGV.collect{|s| s.to_i}