brew install git
mkdir -p ~/code/euler
cd !$
git clone git://gist.github.com/3261313.git problem_1
cd ~/code/euler/problem_1
ruby 1.rb
# We're going to store number that match in here | |
sum = 0 | |
# Use a Range object to iterate over every number from 0 to 1000 (inclusive) | |
(0..1000).each do |n| | |
# Add n to the sum if n is a multiple of 5 or 3 | |
sum += n if n % 5 == 0 || n % 3 == 0 | |
end | |
# Print the answer | |
puts sum |