Skip to content

Instantly share code, notes, and snippets.

@harrisgca
Last active December 29, 2015 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harrisgca/7670652 to your computer and use it in GitHub Desktop.
Save harrisgca/7670652 to your computer and use it in GitHub Desktop.
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