Игорь Пашев - July 5th, 2011

Jul. 5th, 2011

01:09 am - НОД на Рубине

Очень приятный язык.
https://github.com/ip1981/GCD/blob/master/gcd.rb

#!/usr/bin/env ruby

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

# http://railspikes.com/2008/8/11/understanding-map-and-reduce
def gcdn ns
    ns.reduce{ |a, b| gcd2 a, b }
end

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


# ./gcd.rb 121 363 33
11

Tags: , ,
(4 комментария | Оставить комментарий)
Previous day (Calendar) Next day