Solution: LCM of Multiple Numbers Using a Method
Go over the implementation of finding the LCM of a range of numbers with a method in Ruby.
We'll cover the following...
Solution
Press + to interact
def lcm(a, b)(a..a*b).each do |n|if n % a == 0 && n % b == 0return nend # end of ifend # end of loopend # end of methodm = 1(2..15).each do |w|m = lcm(m, w)endputs "The lowest number that is dividable by 1 to 15 is: #{m}"
...