Skip to content

Commit

Permalink
Add project 1 to git project.
Browse files Browse the repository at this point in the history
  • Loading branch information
U-MOZPOWER\Joey Jurabado authored and U-MOZPOWER\Joey Jurabado committed Nov 10, 2008
0 parents commit 4a13dab
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions integer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Integer
def multiples(range)
range.select do |num|
num % self == 0
end
end
end
7 changes: 7 additions & 0 deletions integer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'integer'
describe Integer do
it "should return multiples of 3 for all natural numbers up to 9" do
multiples = 3.multiples(1..9)
multiples.should == [3,6,9]
end
end
9 changes: 9 additions & 0 deletions problem1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'integer'

multiples_of_3 = 3.multiples(1..999)
multiples_of_5 = 5.multiples(1..999)
multiples_of_3.each { |num| multiples_of_3.delete(num) if multiples_of_5.include?(num) }

sum = (multiples_of_3 + multiples_of_5).inject {|sum, multiple| sum + multiple }
puts sum

0 comments on commit 4a13dab

Please sign in to comment.