Proper divisors: Difference between revisions
→{{header|langur}}
Basicgames (talk | contribs) |
Langurmonkey (talk | contribs) |
||
(8 intermediate revisions by 6 users not shown) | |||
Line 2,242:
10: [1, 2, 5]
15120: 79</pre>
=={{header|EasyLang}}==
<syntaxhighlight>
proc propdivs n . divs[] .
divs[] = [ ]
if n < 2
return
.
divs[] &= 1
sqr = sqrt n
for d = 2 to sqr
if n mod d = 0
divs[] &= d
if d <> sqr
divs[] &= n / d
.
.
.
.
for i to 10
propdivs i d[]
write i & ":"
print d[]
.
for i to 20000
propdivs i d[]
if len d[] > max
max = len d[]
maxi = i
.
.
print maxi & " has " & max & " proper divisors."
</syntaxhighlight>
=={{header|EchoLisp}}==
Line 2,762 ⟶ 2,795:
</pre>
=={{header|Frink}}==
Line 3,736 ⟶ 3,694:
=={{header|langur}}==
{{trans|Go}}
<syntaxhighlight lang="langur">val .getproper = fn(.x) for[=[]] .i of .x \ 2 { if .x div .i: _for ~= [.i] }
val .listproper =
if .x < 1: return null
for[=""] .i of .x {
}
}
writeln "The proper divisors of the following numbers are :"
writeln .listproper(10)
var .max = 0
Line 5,889 ⟶ 5,845:
9 -> 1 3
10 -> 1 2 5
</pre>
=={{header|RPL}}==
{{works with|HP|49}}
≪ DIVIS REVLIST TAIL REVLIST <span style="color:grey">@ or DIVIS 1 OVER SIZE 1 - SUB</span>
≫ '<span style="color:blue">PDIVIS</span>' STO
≪ 0 → max n
≪ 0
1 max '''FOR''' j
j <span style="color:blue">PDIVIS</span> SIZE
'''IF''' DUP2 < '''THEN''' SWAP j 'n' STO '''END'''
DROP
'''NEXT'''
DROP n DUP <span style="color:blue">PDIVIS</span> SIZE
≫ ≫ '<span style="color:blue">TASK2</span>' STO
≪ n <span style="color:blue">PDIVIS</span> ≫ 'n' 1 10 1 SEQ
20000 <span style="color:blue">TASK2</span>
{{out}}
<pre>
3: {{} {1} {1} {1 2} {1} {1 2 3} {1} {1 2 4} {1 3} {1 2 5}}
2: 15120
1: 39
</pre>
Line 6,207 ⟶ 6,187:
{{trans|Raku}}
<syntaxhighlight lang="ruby">func propdiv (n) {
n.divisors.
}
Line 6,549 ⟶ 6,529:
{{libheader|Wren-fmt}}
{{libheader|Wren-math}}
<syntaxhighlight lang="
import "./math" for Int
for (i in 1..10) System.print("%(Fmt.d(2, i)) -> %(Int.properDivisors(i))")
|