Here's a simple function to find the least common multiple of two integers using the lcm method in Ruby's math module:
main.rb36 chars4 linesYou can call this function with two integers as arguments and it will return their least common multiple:
main.rb46 chars3 lines
The lcm method returns the least common multiple of two numbers using the formula (a * b) / gcd(a, b), where gcd is the greatest common divisor of the two numbers. The lcm method is a part of the Ruby's Integer class and takes one argument, which is the second number to find lcm of.
gistlibby LogSnag