]> code.delx.au - gnu-emacs-elpa/blob - packages/realgud/test/gcd.rb
c780a313116a3d73ea3dadd3a98f3702274b5104
[gnu-emacs-elpa] / packages / realgud / test / gcd.rb
1 #!/usr/bin/env ruby
2
3 # GCD. We assume positive numbers
4 def gcd(a, b)
5 # Make: a <= b
6 if a > b
7 a, b = [b, a]
8 end
9
10 return nil if a <= 0
11
12 if a == 1 or b-a == 0
13 return a
14 end
15 return gcd(b-a, a)
16 end
17
18 a, b = ARGV[0..1].map {|arg| arg.to_i}
19 puts "The GCD of %d and %d is %d" % [a, b, gcd(a, b)]