diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2011-07-05 01:08:55 +0400 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2011-07-05 01:08:55 +0400 |
commit | 95eaf22587c148a14f7fdd2455de99881a353884 (patch) | |
tree | c273ceacf11b4a864162aa2d8539f6e12f2f7137 | |
parent | 270050462a570dfa1a21fec39007dc1cb81acb91 (diff) | |
download | gcd-95eaf22587c148a14f7fdd2455de99881a353884.tar.gz |
Added Ruby
-rwxr-xr-x | gcd.rb | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -0,0 +1,17 @@ +#!/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} + |