Proper divisors: Difference between revisions

Content added Content deleted
No edit summary
Line 242: Line 242:
Most divisors has 15120 , it has 79 divisors!
Most divisors has 15120 , it has 79 divisors!
</pre>
</pre>

=={{header|Ceylon}}==
<lang ceylon>shared void properDivisors() {

function divisors(Integer int) =>
if(int <= 1) then {} else (1..int / 2).filter((Integer element) => element.divides(int));
for(i in 1..10) {
print("``i`` => ``divisors(i)``");
}
value start = 1;
value end = 20k;
value mostDivisors = (start..end)
// number -> divisors count: {1->0, 2->1, ... 6->3, ...}
.map((Integer element) => element->divisors(element).size)
// group based on the number of divisors
.group((Integer->Integer element) => let(i->count = element) count)
// clean it up a bit
.mapItems((Integer key, [<Integer->Integer>+] item) => item*.key)
// find the group with the most divisors
.max((Integer->[Integer+] x, Integer->[Integer+] y) => x.key <=> y.key);
print("the number(s) with the most divisors between ``start`` and ``end`` is/are:
``mostDivisors?.item else "nothing"`` with ``mostDivisors?.key else "no"`` divisors");
}</lang>
{{out}}
<pre>1 => []
2 => { 1 }
3 => { 1 }
4 => { 1, 2 }
5 => { 1 }
6 => { 1, 2, 3 }
7 => { 1 }
8 => { 1, 2, 4 }
9 => { 1, 3 }
10 => { 1, 2, 5 }
the number(s) with the most divisors between 1 and 20000 is/are:
[15120, 18480] with 79 divisors</pre>


=={{header|D}}==
=={{header|D}}==