Skip to content

Instantly share code, notes, and snippets.

@iamkevinlowe
Created July 5, 2016 16:30
Show Gist options
  • Save iamkevinlowe/6433d6aa6d1f8ba0f052384257f431cc to your computer and use it in GitHub Desktop.
Save iamkevinlowe/6433d6aa6d1f8ba0f052384257f431cc to your computer and use it in GitHub Desktop.
def solve_problem
numbs = Array(1..999)
mults_of_3 = []
mults_of_5 = []
all_mults = []
the_answer = 0
numbs.each do |number|
if number % 3 == 0
mults_of_3 << number
end
end
numbs.each do |number|
if number % 5 == 0
mults_of_5 << number
end
end
all_mults = mults_of_3 + mults_of_5
all_mults = all_mults.flatten
all_mults = all_mults.uniq
all_mults.each do |a_mult|
the_answer = the_answer + a_mult
end
return the_answer
end
puts solve_problem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment