Anonymous user
Sequence of primes by trial division: Difference between revisions
Sequence of primes by trial division (view source)
Revision as of 19:41, 19 January 2018
, 6 years ago→{{header|Julia}}
(add PicoLisp) |
|||
Line 1,144:
=={{header|Julia}}==
{{works with|Julia|0.6}}
I've chosen to solve this task by creating a new iterator type, <tt>TDPrimes</tt>. <tt>TDPrimes</tt> contains the upper limit of the sequence. The iteration state is the list of computed primes, and the item returned with each iteration is the current prime. The core of the solution is the <tt>next</tt> method for <tt>TDPrimes</tt>, which computes the next prime by trial division of the previously determined primes contained in the iteration state.
end
Base.done{T<:Integer}(pl::TDPrimes{T}, p::Vector{T})
pr = npr = p[end]▼
▲function Base.next{T<:Integer}(pl::TDPrimes{T}, p::Array{T,1})
ispr =
▲ ispr = false
▲ end
end
push!(p,
return
end
println("Primes ≤ 100: ", join((p for p in TDPrimes(100)), ", "))</lang>
{{out}}
<pre>Primes ≤
▲ 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
=={{header|jq}}==
|