Skip to content

Instantly share code, notes, and snippets.

@paralleltree
Last active September 5, 2015 03:39
Show Gist options
  • Save paralleltree/133ddfb3175045c4b664 to your computer and use it in GitHub Desktop.
Save paralleltree/133ddfb3175045c4b664 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
if (ARGV.count != 2)
puts 'Invalid number of arguments.'
exit
end
a, b = ARGV.map { |s| s.to_i }
get_gcd = -> (m, n) do
m, n = n, m if m < n
return m if n == 0
get_gcd[n, m % n]
end
gcd = get_gcd[a, b]
puts "#{a} : #{b} = #{a / gcd} : #{b / gcd}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment