Proper divisors: Difference between revisions
Content added Content deleted
(tbas) |
(Added Dyalect programming language) |
||
Line 1,181: | Line 1,181: | ||
Tuple!(uint, int)(79, 18480)</pre> |
Tuple!(uint, int)(79, 18480)</pre> |
||
The Run-time is about 0.67 seconds with the ldc2 compiler. |
The Run-time is about 0.67 seconds with the ldc2 compiler. |
||
=={{header|Dyalect}}== |
|||
{{trans|Swift}} |
|||
<lang dyalect>func properDivs(n) { |
|||
if n == 1 { |
|||
return |
|||
} |
|||
for x in 1..(n-1) { |
|||
if n % x == 0 { |
|||
yield x |
|||
} |
|||
} |
|||
} |
|||
for i in 1..10 { |
|||
print("\(i): \(properDivs(i).toArray())") |
|||
} |
|||
var (num, max) = (0,0) |
|||
for i in 1..20000 { |
|||
const count = properDivs(i).len() |
|||
if count > max { |
|||
set (num, max) = (i, count) |
|||
} |
|||
} |
|||
print("\(num): \(max)")</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] |
|||
15120: 79</pre> |
|||
=={{header|EchoLisp}}== |
=={{header|EchoLisp}}== |