Skip to content

Instantly share code, notes, and snippets.

@finsterthecat
Last active September 26, 2015 23:27
Show Gist options
  • Save finsterthecat/1175976 to your computer and use it in GitHub Desktop.
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
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