Created
November 12, 2015 10:51
-
-
Save bragboy/f76d5b3d5b1f11f177ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| n_s, d_s = [1,1] | |
| 12.upto(97) do |n| | |
| 13.upto(98) do |d| | |
| next if n/10 == n%10 || d/10 == d%10 || n%10 ==0 || d%10 ==0 || n>=d | |
| a,b = [n.to_s.split(//), d.to_s.split(//)] | |
| if (a&b).size == 1 && (a-(a&b))[0].to_f / (b-(a&b))[0].to_f == n.to_f/d.to_f | |
| n_s*=(a-(a&b))[0].to_i | |
| d_s*=(b-(a&b))[0].to_i | |
| end | |
| end | |
| end | |
| puts "The product in its lowest common terms is #{d_s/n_s}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment