Instantly share code, notes, and snippets.

Embed
What would you like to do?
This code produces the wrong answer and I don't know why. It also is bloated code; I've seen other people's 1 line solution LOL edit: 3rd time was the charm!!!
closer = Array.new #create array to hold numbers
for i in 1..999 do #populating array with multiples of 3 and 5
if i % 3 == 0
closer << i
elsif
i % 5 == 0
closer << i
end
end
closer_sum = closer.inject (:+) #compute sum of all numbers in array
puts ""
puts "The answer to Problem 1 on projecteuler.net is #{closer_sum}."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment