Skip to content

Commit e20249e

Browse files
committed
problem 10
1 parent 7bfab8e commit e20249e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

10.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def sieve(below)
2+
total = below - 2#00000
3+
array = [].fill(0 .. total){false}
4+
p = 2
5+
loop do
6+
unless array[p - 2]
7+
2.upto(below / p) do |x|
8+
array[x * p - 2] = true
9+
end
10+
end
11+
p += 1
12+
break if p > total
13+
end
14+
result = []
15+
array.each_index{|index|result << index + 2 unless array[index]}
16+
result
17+
end
18+
p sieve(2000000).inject{|sum, x| sum += x}

0 commit comments

Comments
 (0)