Sum of divisors: Difference between revisions

Added Easylang
(→‎{{header|Nim}}: Added Lua)
(Added Easylang)
 
(5 intermediate revisions by 4 users not shown)
Line 79:
112 168 128 144 120 252 98 171 156 217
</pre>
 
=={{header|ALGOL-M}}==
<syntaxhighlight lang="algolm">begin
integer N;
N := 100;
begin
integer array div[1:N];
integer i, j, col;
for i := 1 step 1 until N do div[i] := 1;
for i := 2 step 1 until N do
for j := i step i until N do
div[j] := div[j] + i;
col := 0;
for i := 1 step 1 until N do begin
if (col-1)/10 <> col/10 then
write(div[i])
else
writeon(div[i]);
col := col + 1;
end;
end;
end</syntaxhighlight>
{{out}}
<pre> 1 3 4 7 6 12 8 15 13 18
12 28 14 24 24 31 18 39 20 42
32 36 24 60 31 42 40 56 30 72
32 63 48 54 48 91 38 60 56 90
42 96 44 84 78 72 48 124 57 93
72 98 54 120 72 120 80 90 60 168
62 96 104 127 84 144 68 126 96 144
72 195 74 114 124 140 96 168 80 186
121 126 84 224 108 132 120 180 90 234
112 168 128 144 120 252 98 171 156 217</pre>
 
=={{header|ALGOL 68}}==
Line 167 ⟶ 133:
112 168 128 144 120 252 98 171 156 217
</pre>
 
=={{header|ALGOL-M}}==
<syntaxhighlight lang="algolm">begin
integer N;
N := 100;
begin
integer array div[1:N];
integer i, j, col;
for i := 1 step 1 until N do div[i] := 1;
for i := 2 step 1 until N do
for j := i step i until N do
div[j] := div[j] + i;
col := 0;
for i := 1 step 1 until N do begin
if (col-1)/10 <> col/10 then
write(div[i])
else
writeon(div[i]);
col := col + 1;
end;
end;
end</syntaxhighlight>
{{out}}
<pre> 1 3 4 7 6 12 8 15 13 18
12 28 14 24 24 31 18 39 20 42
32 36 24 60 31 42 40 56 30 72
32 63 48 54 48 91 38 60 56 90
42 96 44 84 78 72 48 124 57 93
72 98 54 120 72 120 80 90 60 168
62 96 104 127 84 144 68 126 96 144
72 195 74 114 124 140 96 168 80 186
121 126 84 224 108 132 120 180 90 234
112 168 128 144 120 252 98 171 156 217</pre>
 
=={{header|ALGOL W}}==
Line 898:
{$IFNDEF UNIX} readln; {$ENDIF}
end.</syntaxhighlight>
 
=={{header|EasyLang}}==
{{trans|BASIC256}}
<syntaxhighlight>
write 1 & " "
for n = 2 to 100
p = 1 + n
for i = 2 to n div 2
if n mod i = 0
p += i
.
.
write p & " "
.
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
Line 1,097 ⟶ 1,112:
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Sum_of_divisors}}
 
'''Solution'''
 
[[File:Fōrmulæ - Sum of divisors 01.png]]
 
'''Test case 1. Show the result for the first 100 positive integers'''
 
[[File:Fōrmulæ - Sum of divisors 02.png]]
 
[[File:Fōrmulæ - Sum of divisors 03.png]]
 
'''Test case 2. Char'''
 
[[File:Fōrmulæ - Sum of divisors 04.png]]
 
[[File:Fōrmulæ - Sum of divisors 05.png]]
 
=={{header|Go}}==
Line 1,447 ⟶ 1,478:
121 126 84 224 108 132 120 180 90 234
112 168 128 144 120 252 98 171 156 217</pre>
 
=={{header|MAD}}==
<syntaxhighlight lang="mad"> NORMAL MODE IS INTEGER
DIMENSION DIVSUM(100)
THROUGH INIT, FOR I=1, 1, I.G.100
INIT DIVSUM(I) = 1
 
THROUGH CALC, FOR D=2, 1, D.G.100
THROUGH CALC, FOR M=D, D, M.G.100
CALC DIVSUM(M) = DIVSUM(M) + D
 
THROUGH SHOW, FOR I=1, 10, I.G.100
SHOW PRINT FORMAT F, DIVSUM(I), DIVSUM(I+1),
0 DIVSUM(I+2), DIVSUM(I+3), DIVSUM(I+4),
1 DIVSUM(I+5), DIVSUM(I+6), DIVSUM(I+7),
2 DIVSUM(I+8), DIVSUM(I+9)
 
VECTOR VALUES F = $10(I4)*$
END OF PROGRAM </syntaxhighlight>
{{out}}
<pre> 1 3 4 7 6 12 8 15 13 18
12 28 14 24 24 31 18 39 20 42
32 36 24 60 31 42 40 56 30 72
32 63 48 54 48 91 38 60 56 90
42 96 44 84 78 72 48 124 57 93
72 98 54 120 72 120 80 90 60 168
62 96 104 127 84 144 68 126 96 144
72 195 74 114 124 140 96 168 80 186
121 126 84 224 108 132 120 180 90 234
112 168 128 144 120 252 98 171 156 217</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">DivisorSigma[1, Range[100]]</syntaxhighlight>
{{out}}
<pre>{1, 3, 4, 7, 6, 12, 8, 15, 13, 18, 12, 28, 14, 24, 24, 31, 18, 39, 20, 42, 32, 36, 24, 60, 31, 42, 40, 56, 30, 72, 32, 63, 48, 54, 48, 91, 38, 60, 56, 90, 42, 96, 44, 84, 78, 72, 48, 124, 57, 93, 72, 98, 54, 120, 72, 120, 80, 90, 60, 168, 62, 96, 104, 127, 84, 144, 68, 126, 96, 144, 72, 195, 74, 114, 124, 140, 96, 168, 80, 186, 121, 126, 84, 224, 108, 132, 120, 180, 90, 234, 112, 168, 128, 144, 120, 252, 98, 171, 156, 217}</pre>
 
=={{header|Lua}}==
Line 1,536 ⟶ 1,531:
121 126 84 224 108 132 120 180 90 234
112 168 128 144 120 252 98 171 156 217
</pre>
 
=={{header|MAD}}==
<syntaxhighlight lang="mad"> NORMAL MODE IS INTEGER
DIMENSION DIVSUM(100)
THROUGH INIT, FOR I=1, 1, I.G.100
INIT DIVSUM(I) = 1
 
THROUGH CALC, FOR D=2, 1, D.G.100
THROUGH CALC, FOR M=D, D, M.G.100
CALC DIVSUM(M) = DIVSUM(M) + D
 
THROUGH SHOW, FOR I=1, 10, I.G.100
SHOW PRINT FORMAT F, DIVSUM(I), DIVSUM(I+1),
0 DIVSUM(I+2), DIVSUM(I+3), DIVSUM(I+4),
1 DIVSUM(I+5), DIVSUM(I+6), DIVSUM(I+7),
2 DIVSUM(I+8), DIVSUM(I+9)
 
VECTOR VALUES F = $10(I4)*$
END OF PROGRAM </syntaxhighlight>
{{out}}
<pre> 1 3 4 7 6 12 8 15 13 18
12 28 14 24 24 31 18 39 20 42
32 36 24 60 31 42 40 56 30 72
32 63 48 54 48 91 38 60 56 90
42 96 44 84 78 72 48 124 57 93
72 98 54 120 72 120 80 90 60 168
62 96 104 127 84 144 68 126 96 144
72 195 74 114 124 140 96 168 80 186
121 126 84 224 108 132 120 180 90 234
112 168 128 144 120 252 98 171 156 217</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">DivisorSigma[1, Range[100]]</syntaxhighlight>
{{out}}
<pre>{1, 3, 4, 7, 6, 12, 8, 15, 13, 18, 12, 28, 14, 24, 24, 31, 18, 39, 20, 42, 32, 36, 24, 60, 31, 42, 40, 56, 30, 72, 32, 63, 48, 54, 48, 91, 38, 60, 56, 90, 42, 96, 44, 84, 78, 72, 48, 124, 57, 93, 72, 98, 54, 120, 72, 120, 80, 90, 60, 168, 62, 96, 104, 127, 84, 144, 68, 126, 96, 144, 72, 195, 74, 114, 124, 140, 96, 168, 80, 186, 121, 126, 84, 224, 108, 132, 120, 180, 90, 234, 112, 168, 128, 144, 120, 252, 98, 171, 156, 217}</pre>
 
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">
divisorSum = function(n)
ans = 0
i = 1
while i * i <= n
if n % i == 0 then
ans += i
j = floor(n / i)
if j != i then ans += j
end if
i += 1
end while
return ans
end function
 
sums = []
for n in range(1, 100)
sums.push(divisorSum(n))
end for
 
print sums.join(", ")
</syntaxhighlight>
{{out}}
<pre>
1, 3, 4, 7, 6, 12, 8, 15, 13, 18, 12, 28, 14, 24, 24, 31, 18, 39, 20, 42, 32, 36, 24, 60, 31, 42, 40, 56, 30, 72, 32, 63, 48, 54, 48, 91, 38, 60, 56, 90, 42, 96, 44, 84, 78, 72, 48, 124, 57, 93, 72, 98, 54, 120, 72, 120, 80, 90, 60, 168, 62, 96, 104, 127, 84, 144, 68, 126, 96, 144, 72, 195, 74, 114, 124, 140, 96, 168, 80, 186, 121, 126, 84, 224, 108, 132, 120, 180, 90, 234, 112, 168, 128, 144, 120, 252, 98, 171, 156, 217
</pre>
 
Line 2,263 ⟶ 2,322:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int, Nums
import "./fmt" for Fmt
 
System.print("The sums of positive divisors for the first 100 positive integers are:")
1,983

edits