Commit e20ea60

mo khan <mo@mokhan.ca>
2014-02-28 22:01:22
finish problem one from project euler.
1 parent 31df012
Changed files (1)
spec/euler/problem_one_spec.rb
@@ -1,13 +1,20 @@
 require "spec_helper"
 
+def sum_of_all_multiples_under(number)
+  matches = ->  (n) { n % 3 == 0 || n % 5 == 0 }
+  (0...number).inject(0) do |sum, next_number|
+    matches.call(next_number) ? sum + next_number : sum
+  end
+end
+
 describe "problem 1" do
   it "finds the sum of all multiples of 3 or 5 below 10" do
     result = sum_of_all_multiples_under(10)
     result.should == 23
   end
 
-  xit "finds the sum of all multiples of 3 or 5 below 1000" do
-    result = sum_of_all_multiples_under(10)
-    result.should == 0
+  it "finds the sum of all multiples of 3 or 5 below 1000" do
+    result = sum_of_all_multiples_under(1000)
+    result.should == 233_168
   end
 end