Proper divisors: Difference between revisions

Added AutoHotkey
m (→‎{{header|Phix}}: forgot 0)
(Added AutoHotkey)
Line 896:
 
</pre>
 
=={{header|AutoHotkey}}==
<lang AutoHotkey>proper_divisors(n) {
Array := []
Array[1] := true
if n = 1
return Array
x := Floor(Sqrt(n))
loop, % x+1
if !Mod(n, i:=A_Index+1)
Array[floor(n/i)] := true
Loop % n/x
if !Mod(n, i:=A_Index+1)
Array[i] := true
return Array
}</lang>
Examples:<lang AutoHotkey>output := "Number`tDivisors`tCount`n"
loop, 10
{
output .= A_Index "`t"
for n, bool in x := proper_divisors(A_Index)
output .= n " "
output .= "`t" x.count() "`n"
}
maxDiv := 0, numDiv := []
loop, 20000
{
Arr := proper_divisors(A_Index)
numDiv[Arr.count()] := (numDiv[Arr.count()] ? numDiv[Arr.count()] ", " : "") A_Index
maxDiv := maxDiv > Arr.count() ? maxDiv : Arr.count()
}
output .= "`nNumber(s) in the range 1 to 20,000 with the most proper divisors:`n" numDiv.Pop() " with " maxDiv " divisors"
MsgBox % output
return</lang>
{{out}}
<pre>Number Divisors Count
1 1 1
2 1 2 2
3 1 3 2
4 1 2 2
5 1 1
6 1 2 3 3
7 1 1
8 1 2 4 3
9 1 3 2
10 1 2 5 3
 
Number(s) in the range 1 to 20,000 with the most proper divisors:
15120, 18480 with 79 divisors</pre>
 
=={{header|AWK}}==
299

edits