Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
19
Task/Proper-divisors/Ada/proper-divisors-1.adb
Normal file
19
Task/Proper-divisors/Ada/proper-divisors-1.adb
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
generic
|
||||
type Result_Type (<>) is limited private;
|
||||
None: Result_Type;
|
||||
with function One(X: Positive) return Result_Type;
|
||||
with function Add(X, Y: Result_Type) return Result_Type
|
||||
is <>;
|
||||
package Generic_Divisors is
|
||||
|
||||
function Process
|
||||
(N: Positive; First: Positive := 1) return Result_Type is
|
||||
(if First**2 > N or First = N then None
|
||||
elsif (N mod First)=0 then
|
||||
(if First = 1 or First*First = N
|
||||
then Add(One(First), Process(N, First+1))
|
||||
else Add(One(First),
|
||||
Add(One((N/First)), Process(N, First+1))))
|
||||
else Process(N, First+1));
|
||||
|
||||
end Generic_Divisors;
|
||||
59
Task/Proper-divisors/Ada/proper-divisors-2.adb
Normal file
59
Task/Proper-divisors/Ada/proper-divisors-2.adb
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
with Ada.Text_IO, Ada.Containers.Generic_Array_Sort, Generic_Divisors;
|
||||
|
||||
procedure Proper_Divisors is
|
||||
|
||||
begin
|
||||
-- show the proper divisors of the numbers 1 to 10 inclusive.
|
||||
declare
|
||||
type Pos_Arr is array(Positive range <>) of Positive;
|
||||
subtype Single_Pos_Arr is Pos_Arr(1 .. 1);
|
||||
Empty: Pos_Arr(1 .. 0);
|
||||
|
||||
function Arr(P: Positive) return Single_Pos_Arr is ((others => P));
|
||||
|
||||
package Divisor_List is new Generic_Divisors
|
||||
(Result_Type => Pos_Arr, None => Empty, One => Arr, Add => "&");
|
||||
|
||||
procedure Sort is new Ada.Containers.Generic_Array_Sort
|
||||
(Positive, Positive, Pos_Arr);
|
||||
begin
|
||||
for I in 1 .. 10 loop
|
||||
declare
|
||||
List: Pos_Arr := Divisor_List.Process(I);
|
||||
begin
|
||||
Ada.Text_IO.Put
|
||||
(Positive'Image(I) & " has" &
|
||||
Natural'Image(List'Length) & " proper divisors:");
|
||||
Sort(List);
|
||||
for Item of List loop
|
||||
Ada.Text_IO.Put(Positive'Image(Item));
|
||||
end loop;
|
||||
Ada.Text_IO.New_Line;
|
||||
end;
|
||||
end loop;
|
||||
end;
|
||||
|
||||
-- find a number 1 .. 20,000 with the most proper divisors
|
||||
declare
|
||||
Number: Positive := 1;
|
||||
Number_Count: Natural := 0;
|
||||
Current_Count: Natural;
|
||||
|
||||
function Cnt(P: Positive) return Positive is (1);
|
||||
|
||||
package Divisor_Count is new Generic_Divisors
|
||||
(Result_Type => Natural, None => 0, One => Cnt, Add => "+");
|
||||
|
||||
begin
|
||||
for Current in 1 .. 20_000 loop
|
||||
Current_Count := Divisor_Count.Process(Current);
|
||||
if Current_Count > Number_Count then
|
||||
Number := Current;
|
||||
Number_Count := Current_Count;
|
||||
end if;
|
||||
end loop;
|
||||
Ada.Text_IO.Put_Line
|
||||
(Positive'Image(Number) & " has the maximum number of" &
|
||||
Natural'Image(Number_Count) & " proper divisors.");
|
||||
end;
|
||||
end Proper_Divisors;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
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
|
||||
|
|
|
|||
15
Task/Proper-divisors/Maxima/proper-divisors.maxima
Normal file
15
Task/Proper-divisors/Maxima/proper-divisors.maxima
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
proper_divisors(n) := disjoin(n, divisors(n))$
|
||||
for i from 1 thru 10 do sprint(i, ":", proper_divisors(i))$
|
||||
|
||||
pdivcount(n) := cardinality(proper_divisors(n))$
|
||||
block(
|
||||
maxdivs: 1, nmax: 1,
|
||||
for i from 1 thru 20000 do(
|
||||
divs: pdivcount(i),
|
||||
if divs > maxdivs then block(
|
||||
maxdivs: divs,
|
||||
nmax: i
|
||||
)
|
||||
),
|
||||
sprint(nmax, "has", maxdivs, "proper divisors.")
|
||||
)$
|
||||
18
Task/Proper-divisors/Pluto/proper-divisors.pluto
Normal file
18
Task/Proper-divisors/Pluto/proper-divisors.pluto
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
local int = require "int"
|
||||
local fmt = require "fmt"
|
||||
|
||||
for i = 1, 10 do
|
||||
fmt.print("%2d -> %s", i, fmt.swrite(int.divisors(i, true)))
|
||||
end
|
||||
|
||||
print("\nThe number in the range {1, 20,000} with the most proper divisors is:")
|
||||
local number = 1
|
||||
local max_divs = 0
|
||||
for i = 2, 20_000 do
|
||||
local [divs, _] = int.divstat(i, true)
|
||||
if divs > max_divs then
|
||||
number = i
|
||||
max_divs = divs
|
||||
end
|
||||
end
|
||||
print($"{fmt.int(number)} which has {max_divs} proper divisors.")
|
||||
17
Task/Proper-divisors/PowerShell/proper-divisors-1.ps1
Normal file
17
Task/Proper-divisors/PowerShell/proper-divisors-1.ps1
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
function proper-divisor ($n) {
|
||||
if($n -ge 2) {
|
||||
$lim = [Math]::Floor([Math]::Sqrt($n))
|
||||
$less, $greater = @(1), @()
|
||||
for($i = 2; $i -lt $lim; $i++){
|
||||
if($n%$i -eq 0) {
|
||||
$less += @($i)
|
||||
$greater = @($n/$i) + $greater
|
||||
}
|
||||
}
|
||||
if(($lim -ne 1) -and ($n%$lim -eq 0)) {$less += @($lim)}
|
||||
$($less + $greater)
|
||||
} else {@()}
|
||||
}
|
||||
"$(proper-divisor 100)"
|
||||
"$(proper-divisor 496)"
|
||||
"$(proper-divisor 2048)"
|
||||
15
Task/Proper-divisors/PowerShell/proper-divisors-2.ps1
Normal file
15
Task/Proper-divisors/PowerShell/proper-divisors-2.ps1
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
function proper-divisor ($n) {
|
||||
if($n -ge 2) {
|
||||
$lim = [Math]::Floor($n/2)+1
|
||||
$proper = @(1)
|
||||
for($i = 2; $i -lt $lim; $i++){
|
||||
if($n%$i -eq 0) {
|
||||
$proper += @($i)
|
||||
}
|
||||
}
|
||||
$proper
|
||||
} else {@()}
|
||||
}
|
||||
"$(proper-divisor 100)"
|
||||
"$(proper-divisor 496)"
|
||||
"$(proper-divisor 2048)"
|
||||
49
Task/Proper-divisors/PowerShell/proper-divisors-3.ps1
Normal file
49
Task/Proper-divisors/PowerShell/proper-divisors-3.ps1
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
function eratosthenes ($n) {
|
||||
if($n -gt 1){
|
||||
$prime = @(0..$n| foreach{$true})
|
||||
$m = [Math]::Floor([Math]::Sqrt($n))
|
||||
function multiple($i) {
|
||||
for($j = $i*$i; $j -le $n; $j += $i) {
|
||||
$prime[$j] = $false
|
||||
}
|
||||
}
|
||||
multiple 2
|
||||
for($i = 3; $i -le $m; $i += 2) {
|
||||
if($prime[$i]) {multiple $i}
|
||||
}
|
||||
2
|
||||
for($i = 3; $i -le $n; $i += 2) {
|
||||
if($prime[$i]) {$i}
|
||||
}
|
||||
|
||||
} else {
|
||||
Write-Error "$n is not greater than 1"
|
||||
}
|
||||
}
|
||||
function prime-decomposition ($n) {
|
||||
$array = eratosthenes $n
|
||||
$prime = @()
|
||||
foreach($p in $array) {
|
||||
while($n%$p -eq 0) {
|
||||
$n /= $p
|
||||
$prime += @($p)
|
||||
}
|
||||
}
|
||||
$prime
|
||||
}
|
||||
function proper-divisor ($n) {
|
||||
if($n -ge 2) {
|
||||
$array = prime-decomposition $n
|
||||
$lim = $array.Count
|
||||
function state($res, $i){
|
||||
if($i -lt $lim) {
|
||||
state ($res) ($i + 1)
|
||||
state ($res*$array[$i]) ($i + 1)
|
||||
} elseif($res -lt $n) {$res}
|
||||
}
|
||||
state 1 0 | sort -Unique
|
||||
} else {@()}
|
||||
}
|
||||
"$(proper-divisor 100)"
|
||||
"$(proper-divisor 496)"
|
||||
"$(proper-divisor 2048)"
|
||||
Loading…
Add table
Add a link
Reference in a new issue