Last active
December 29, 2015 12:29
-
-
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!!!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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