Proper divisors: Difference between revisions

Content added Content deleted
(Fixed D entry according to the Python entry)
Line 15: Line 15:


=={{header|D}}==
=={{header|D}}==
{{incorrect|D|1 has no proper divisors.}}
{{trans|Python}}
{{trans|Python}}
Currently the lambda of the filter allocates a closure on the GC-managed heap.
Currently the lambda of the filter allocates a closure on the GC-managed heap.
Line 22: Line 21:


immutable properDivs = (in uint n) pure nothrow @safe /*@nogc*/ =>
immutable properDivs = (in uint n) pure nothrow @safe /*@nogc*/ =>
iota(1, (n + 1) / 2 + 1).filter!(x => n % x == 0);
iota(1, (n + 1) / 2 + 1).filter!(x => n % x == 0 && n != x);


iota(1, 11).map!properDivs.writeln;
iota(1, 11).map!properDivs.writeln;
Line 28: Line 27:
}</lang>
}</lang>
{{out}}
{{out}}
<pre>[[1], [1], [1], [1, 2], [1], [1, 2, 3], [1], [1, 2, 4], [1, 3], [1, 2, 5]]
<pre>[[], [1], [1], [1, 2], [1], [1, 2, 3], [1], [1, 2, 4], [1, 3], [1, 2, 5]]
Tuple!(uint, int)(79, 18480)</pre>
Tuple!(uint, int)(79, 18480)</pre>
The Run-time is about 0.71 seconds with the ldc2 compiler.
The Run-time is about 0.67 seconds with the ldc2 compiler.


=={{header|J}}==
=={{header|J}}==