Data update
This commit is contained in:
parent
29a5eea0d4
commit
5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions
35
Task/Proper-divisors/Chipmunk-Basic/proper-divisors.basic
Normal file
35
Task/Proper-divisors/Chipmunk-Basic/proper-divisors.basic
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
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
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
proc propdivs n . divs[] .
|
||||
divs[] = [ ]
|
||||
func[] propdivs n .
|
||||
if n < 2
|
||||
return
|
||||
return [ ]
|
||||
.
|
||||
divs[] &= 1
|
||||
sqr = sqrt n
|
||||
|
|
@ -13,14 +12,13 @@ proc propdivs n . divs[] .
|
|||
.
|
||||
.
|
||||
.
|
||||
return divs[]
|
||||
.
|
||||
for i to 10
|
||||
propdivs i d[]
|
||||
write i & ":"
|
||||
print d[]
|
||||
print i & ":" & propdivs i
|
||||
.
|
||||
for i to 20000
|
||||
propdivs i d[]
|
||||
d[] = propdivs i
|
||||
if len d[] > max
|
||||
max = len d[]
|
||||
maxi = i
|
||||
|
|
|
|||
47
Task/Proper-divisors/Gambas/proper-divisors.gambas
Normal file
47
Task/Proper-divisors/Gambas/proper-divisors.gambas
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
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
|
||||
|
|
@ -1,26 +1,26 @@
|
|||
val .getproper = fn(.x) for[=[]] .i of .x \ 2 { if .x div .i: _for ~= [.i] }
|
||||
val .cntproper = fn(.x) for[=0] .i of .x \ 2 { if .x div .i: _for += 1 }
|
||||
val getproper = fn x: for[=[]] i of x \ 2 { if x div i: _for ~= [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"
|
||||
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)
|
||||
writeln listproper(10)
|
||||
|
||||
var .max = 0
|
||||
var .most = []
|
||||
for .n in 2 .. 20_000 {
|
||||
val .cnt = .cntproper(.n)
|
||||
if .cnt == .max {
|
||||
.most = more .most, .n
|
||||
} else if .cnt > .max {
|
||||
.max, .most = .cnt, [.n]
|
||||
var mx = 0
|
||||
var most = []
|
||||
for n in 2 .. 20_000 {
|
||||
val cnt = cntproper(n)
|
||||
if cnt == mx {
|
||||
most = more(most, n)
|
||||
} else if cnt > mx {
|
||||
mx, most = cnt, [n]
|
||||
}
|
||||
}
|
||||
|
||||
writeln $"The following number(s) <= 20000 have the most proper divisors (\.max;)"
|
||||
writeln .most
|
||||
writeln "The following number(s) <= 20000 have the most proper divisors ({{mx}})"
|
||||
writeln most
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue