Permalink
Browse files

Solved problem 10

  • Loading branch information...
1 parent 77c01f5 commit d14be22d41a513099b585a68590b2ecf6c354270 @cmpolis committed Aug 15, 2010
Showing with 18 additions and 0 deletions.
  1. BIN .Problem7.rb.swp
  2. +18 −0 Problem10.rb
View
Binary file not shown.
View
@@ -0,0 +1,18 @@
+start_time = Time.now
+
+# From problem 7 soution
+class Fixnum
+ def prime?
+ (3..Math.sqrt(self)).all? { |i| self % i != 0 }
+ end
+end
+
+# Assume 2 is prime, allows checking only odds
+sum = 2
+test_num = 3
+while test_num < 2000000
+ sum += test_num.prime? ? test_num : 0
+ test_num += 2
+end
+puts sum
+puts Time.now - start_time

0 comments on commit d14be22

Please sign in to comment.