...

/

Solution: LCM of Multiple Numbers Using a Method

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 == 0
return n
end # end of if
end # end of loop
end # end of method
m = 1
(2..15).each do |w|
m = lcm(m, w)
end
puts "The lowest number that is dividable by 1 to 15 is: #{m}"
...