Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Solved problem 10

  • Loading branch information...
commit d14be22d41a513099b585a68590b2ecf6c354270 1 parent 77c01f5
@cmpolis authored
Showing with 18 additions and 0 deletions.
  1. BIN  .Problem7.rb.swp
  2. +18 −0 Problem10.rb
View
BIN  .Problem7.rb.swp
Binary file not shown
View
18 Problem10.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.