From 95eaf22587c148a14f7fdd2455de99881a353884 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Tue, 5 Jul 2011 01:08:55 +0400 Subject: Added Ruby --- gcd.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 gcd.rb diff --git a/gcd.rb b/gcd.rb new file mode 100755 index 0000000..0eefe8a --- /dev/null +++ b/gcd.rb @@ -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} + -- cgit v1.2.3