The first problem of Project Euler is very straight forward.

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

This problem is basically making sure that the site user has a computer language at their disposal and a basic grasp of common operations such as looping, if/else, and the modulo operator.

My straight forward Ruby code is below. Note that I write every Ruby program so that it can be run as an executable script that takes a value from the command line. This value is typically assigned to @n within my code. It’s used for problems that solve a general case. The general case of this problem is to find the sum of all the multiples of 3 or 5 below N.

[sourcecode language=“ruby”]

#!/usr/bin/env ruby

class Problem

# Create the object

def initialize (n = 10)

@n = n.to_i

@sum = 0

end

# Solve it

def solve

puts “Find sum of all numbers under #{@n} disivible by 3 and 5″

@n.times do |k|

@sum += k if k % 3 == 0 || k % 5 == 0

end

puts “Solution: #{@sum} is solution for n = #{@n}“

end

end

if __FILE__ == $0

# Initialize the program

p = Problem.new ARGV[0] || 10

p.solve

end

[/sourcecode]