Proper divisors: Difference between revisions

Added various BASIC dialects (Chipmunk Basic and Gambas)
(Added various BASIC dialects (Chipmunk Basic and Gambas))
 
(2 intermediate revisions by 2 users not shown)
Line 1,252:
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
{{works with|QB64}}
<syntaxhighlight lang="qbasic">FUNCTION CountProperDivisors (number)
IF number < 2 THEN CountProperDivisors = 0
Line 1,343 ⟶ 1,344:
Igual que la entrada de FreeBASIC o PureBasic.
</pre>
 
==={{header|Chipmunk Basic}}===
{{trans|BASIC}}
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="vbnet">100 cls
110 most = 1
120 maxcount = 0
130 print "The proper divisors of the following numbers are: ";chr$(10)
140 listproperdivisors(10)
150 for n = 2 to 20000
160 rem It is extremely slow in this loop
170 count = countproperdivisors(n)
180 if count > maxcount then
190 maxcount = count
200 most = n
210 endif
220 next n
230 print
240 print most;" has the most proper divisors, namely ";maxcount
250 end
260 function countproperdivisors(number)
270 if number < 2 then countproperdivisors = 0
280 count = 0
290 for i = 1 to int(number/2)
300 if number mod i = 0 then count = count+1
310 next i
320 countproperdivisors = count
330 end function
340 sub listproperdivisors(limit)
350 if limit < 1 then exit sub
360 for i = 1 to limit
370 print using "## ->";i;
380 if i = 1 then print " (None)";
390 for j = 1 to int(i/2)
400 if i mod j = 0 then print " ";j;
410 next j
420 print
430 next i
440 end sub</syntaxhighlight>
 
==={{header|Craft Basic}}===
Line 1,417 ⟶ 1,457:
15120 has the most proper divisors, namely 79
</pre>
 
==={{header|Gambas}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">Sub ListProperDivisors(limit As Integer)
 
If limit < 1 Then Return
For i As Integer = 1 To limit
Print Format$(i, "## ->");
If i = 1 Then
Print " (None)"
Continue
End If
For j As Integer = 1 To i \ 2
If i Mod j = 0 Then Print " "; j;
Next
Print
Next
 
End Sub
 
Function CountProperDivisors(number As Integer) As Integer
 
If number < 2 Then Return 0
Dim count As Integer = 0
For i As Integer = 1 To number \ 2
If number Mod i = 0 Then count += 1
Next
Return count
 
End Function
 
Public Sub Main()
Dim n As Integer, count As Integer, most As Integer = 1, maxCount As Integer = 0
Print "The proper divisors of the following numbers are: \n"
ListProperDivisors(10)
For n As Integer = 2 To 20000
count = CountProperDivisors(n)
If count > maxCount Then
maxCount = count
most = n
End If
Next
Print
Print most; " has the most proper divisors, namely "; maxCount
End</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|True BASIC}}===
Line 1,508 ⟶ 1,600:
Igual que la entrada de FreeBASIC o PureBasic.
</pre>
 
 
=={{header|BaCon}}==
Line 3,706 ⟶ 3,797:
=={{header|langur}}==
{{trans|Go}}
<syntaxhighlight lang="langur">val .getproper = fn .x: for[=[]] .i of .x \ 2 { if .x div .i: _for ~= [.i] }
val .cntpropergetproper = fn .x: for[=0[]] .i of .x \ 2 { if .x div .i: _for +~= 1[i] }
val cntproper = fn x: for[=0] i of x \ 2 { if x div i: _for += 1 }
 
val .listproper = fn(.x) {
if .x < 1: return null
for[=""] .i of .x {
_for ~= "{{.i:2}} -> {{.getproper(.i)}}\n"
}
}
 
writeln "The proper divisors of the following numbers are :"
writeln .listproper(10)
 
var .maxmx = 0
var .most = []
for .n in 2 .. 20_000 {
val .cnt = .cntproper(.n)
if .cnt == .maxmx {
.most = more .(most, .n)
} else if .cnt > .maxmx {
.maxmx, .most = .cnt, [.n]
}
}
 
writeln "The following number(s) <= 20000 have the most proper divisors ({{.maxmx}})"
writeln .most
</syntaxhighlight>
 
2,169

edits