Anti-primes: Difference between revisions

m (added to prime number category.)
(→‎{{header|Ruby}}: Added Ruby)
Line 1,070:
{{out|output|text=&nbsp; is identical to the 1<sup>st</sup> REXX version.}} <br><br>
 
=={{header|Ruby}}==
<lang ruby>require 'prime'
 
def num_divisors(n)
n.prime_division.inject(1){|prod, (_p,n)| prod *= (n + 1) }
end
 
anti_primes = Enumerator.new do |y| # y is the yielder
max = 0
y << 1 # yield 1
2.step(nil,2) do |candidate|
num = num_divisors(candidate)
if num > max
y << candidate # yield the candidate
max = num
end
end
end
 
puts anti_primes.take(20).join(" ")
</lang>
{{out}}
<pre>
1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560
</pre>
=={{header|Sidef}}==
Using the built-in ''Number.sigma0'' method to count the number of divisors.
1,149

edits