given a ratio (ex. 374:266 or 724.36292:740.37872) how do I get the smallest ratio? 187:133 for the first ex. Now for the second ex, that is a tricker answer. Do I convert to integer and then calculate the smallest ratio? I think I am leaning that way.

Also, 187:133 seems a bit large. Next question is how to identify a smaller ratio that is "close"? say within 2 or 3 decimal places? this example ratio is about 1.4060:1 or I guess I could say 14.06:10 then about 7:5? Not sure if I'm even close to the right track on this.

Be nice if there were already a gem that did this calculation. But I can write a method once I find a correct algorithm. I've tried google searching, but keep getting either web pages that do a Ratio Simplifier or things about gem stone ratios.

NOTE: this is not for Rails. It is for a process that I'm writing. Will be ran on my mac locally only.

$ ruby -v

ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20]

$ uname -a

Darwin far-wa.local 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64

def ratio_simplifier( x, y )

return nil if x.nil? or y.nil?

x = x.round

y = y.round

# do math magic here

# ...

return "#{x}:#{y}"

end # ratio_simplifier

puts ratio_simplifier 374, 266

Thanks for any insight

Eric

ruby-talk@far.tips