Skip to content

Instantly share code, notes, and snippets.

@yanks
Created May 24, 2012 18:28
Show Gist options
  • Save yanks/2783322 to your computer and use it in GitHub Desktop.
Save yanks/2783322 to your computer and use it in GitHub Desktop.
def multiples(num,max)
ret_val = []
max.times() do |i|
ret_val << i if i%num == 0
end
ret_val
end
require 'set'
divisors = Set.new
divisors.merge( multiples(3, 1000) )
divisors.merge( multiples(5, 1000) )
pretty_print = divisors.to_a.sort { |x,y| x <=> y }
puts pretty_print
puts "total #{pretty_print.inject(:+)}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment