Last active
September 26, 2015 23:27
-
-
Save finsterthecat/1175976 to your computer and use it in GitHub Desktop.
Euler Problem #5 in Ruby - Smallest number divisible by each number in 1..20
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
factors = [] | |
(1..20).each do |x| | |
rem = x | |
factors.each do |f| | |
rem /= f if rem % f == 0 | |
end | |
factors << rem if rem > 1 | |
end | |
puts "The answer is... " + factors.inject(1) {|prod, f| prod *= f}.to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment