repo.or.cz
/
ruby-svn.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
history
|
raw
|
HEAD
* io.c (rb_open_file): encoding in mode string was ignored if perm is
[ruby-svn.git]
/
sample
/
sieve.rb
blob
e0bb21d640879173d6c6f9ad1eaabe6e3928f00d
1
# sieve of Eratosthenes
2
max = Integer(ARGV.shift || 100)
3
sieve = []
4
for i in 2 .. max
5
sieve[i] = i
6
end
7
8
for i in 2 .. Math.sqrt(max)
9
next unless sieve[i]
10
(i*i).step(max, i) do |j|
11
sieve[j] = nil
12
end
13
end
14
puts sieve.compact.join(", ")