⚲
Project
General
Profile
Sign in
Register
Home
Projects
Help
Search
:
Ruby master
All Projects
Ruby
»
Ruby master
Overview
Activity
Roadmap
Issues
Repository
Like
Download (528 Bytes)
Bug #11953
» nth_prime.rb
Breaking code -
claytonflesher (Clayton Flesher)
, 01/05/2016 06:59 PM
class
Prime
def
self
.
nth
(
num
)
error
(
num
)
primes
=
build_primes
(
num
)
primes
.
last
end
private
def
build_primes
(
num
)
primes
=
[
2
]
index
=
3
until
primes
.
size
==
num
if
example?
(
index
,
primes
)
primes
<<
index
end
index
+=
1
end
primes
end
def
error
(
num
)
unless
num
>
0
raise
ArgumentError
end
end
def
example?
(
index
,
primes
)
primes
.
each
do
|
prime
|
if
index
%
prime
==
0
return
false
end
end
true
end
end
« Previous
1
2
3
Next »
(1-1/3)
Loading...