Almost prime: Difference between revisions

m
→‎{{header|Julia}}: remove outdated version
m (→‎optimized version: added highlighting to wording in the REXX section header.)
m (→‎{{header|Julia}}: remove outdated version)
Line 1,512:
 
=={{header|Julia}}==
{{works with|Julia|0.6}}
<lang julia>using Primes
 
isalmostprime(n::Integer, k::Integer) = sum(values(factor(n))) == k
 
function almostprimes(N::Integer, k::Integer) # return first N almost-k primes
P = Vector{typeof(k)}(N)
i = 0; n = 2
while i < N
if isalmostprime(n, k) P[i += 1] = n end
n += 1
end
return P
end
 
for k in 1:5
println("$k-Almost-primes: ", join(almostprimes(10, k), ", "), "...")
end</lang>
 
{{out}}
<pre>1-Almost-primes: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29...
2-Almost-primes: 4, 6, 9, 10, 14, 15, 21, 22, 25, 26...
3-Almost-primes: 8, 12, 18, 20, 27, 28, 30, 42, 44, 45...
4-Almost-primes: 16, 24, 36, 40, 54, 56, 60, 81, 84, 88...
5-Almost-primes: 32, 48, 72, 80, 108, 112, 120, 162, 168, 176...</pre>
 
{{works with|Julia|1.1}}
<lang julia>using Primes