Skip to content

Instantly share code, notes, and snippets.

@Whitespace
Forked from anonymous/euler problem 1
Created August 5, 2012 03:07
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 Whitespace/3261313 to your computer and use it in GitHub Desktop.
Save Whitespace/3261313 to your computer and use it in GitHub Desktop.
# 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

Installation

Install git

brew install git

Clone the gist repo

mkdir -p ~/code/euler
cd !$
git clone git://gist.github.com/3261313.git problem_1

Run the program

cd ~/code/euler/problem_1
ruby 1.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment