DEV Community

Discussion on: Project Euler #1 - Multiples of 3 and 5

Collapse
 
hanachin profile image
Seiei Miyagi

Ruby✨💎✨

require "set"

multiples_of_3 = Enumerator.new {|y| x = 0; y << x while x += 3 }
multiples_of_5 = Enumerator.new {|y| x = 0; y << x while x += 5 }

puts [multiples_of_3, multiples_of_5].each_with_object(Set.new) { |e, s|
  s.merge(e.take_while(&1000.method(:>)))
}.sum