In Ruby, what would be the most efficient way to find the smallest
number that an array of different numbers can be divided by with integer
math?
For example:
[1,2] would return 2
[1,2,3] would return 6
[1,2,4] would return 4
[1,2,3,4] would return 12
Somehow your wording puzzles me: you write that you look for the
smallest number that an array can be divided by but yet you rather seem
to be looking for the smallest number that can be divided by all numbers
in the array. I think Rob is spot on with his suggestion.
Somehow your wording puzzles me: you write that you look for the
smallest number that an array can be divided by but yet you rather seem
to be looking for the smallest number that can be divided by all numbers
in the array. I think Rob is spot on with his suggestion.
Yepp, I got it reversed. Using inject and lcm worked great!
Best regards,
Jari W.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.