Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,19 +0,0 @@
|
|||
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;
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
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,33 +1,31 @@
|
|||
-->
|
||||
<span style="color: #008080;">global</span> <span style="color: #008080;">function</span> <span style="color: #7060A8;">factors</span><span style="color: #0000FF;">(</span><span style="color: #004080;">atom</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">include1</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #000080;font-style:italic;">--
|
||||
-- returns a list of all integer factors of n
|
||||
-- if include1 is 0 (the default), result does not contain either 1 or n
|
||||
-- if include1 is 1 the result contains 1 and n
|
||||
-- if include1 is -1 the result contains 1 but not n
|
||||
-- </span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #0000FF;">{}</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #000000;">check_limits</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"factors"</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">lfactors</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{},</span> <span style="color: #000000;">hfactors</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
|
||||
<span style="color: #004080;">atom</span> <span style="color: #000000;">hfactor</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">p</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">2</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">lim</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sqrt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">))</span>
|
||||
global function factors(atom n, integer include1=0)
|
||||
--
|
||||
-- returns a list of all integer factors of n
|
||||
-- if include1 is 0 (the default), result does not contain either 1 or n
|
||||
-- if include1 is 1 the result contains 1 and n
|
||||
-- if include1 is -1 the result contains 1 but not n
|
||||
--
|
||||
if n=0 then return {} end if
|
||||
check_limits(n,"factors")
|
||||
sequence lfactors = {}, hfactors = {}
|
||||
atom hfactor
|
||||
integer p = 2,
|
||||
lim = floor(sqrt(n))
|
||||
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">include1</span><span style="color: #0000FF;">!=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #000000;">lfactors</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">1</span><span style="color: #0000FF;">}</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">!=</span><span style="color: #000000;">1</span> <span style="color: #008080;">and</span> <span style="color: #000000;">include1</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #000000;">hfactors</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">n</span><span style="color: #0000FF;">}</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #008080;">while</span> <span style="color: #000000;">p</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">lim</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">p</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #000000;">lfactors</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">lfactors</span><span style="color: #0000FF;">,</span><span style="color: #000000;">p</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #000000;">hfactor</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">/</span><span style="color: #000000;">p</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">hfactor</span><span style="color: #0000FF;">=</span><span style="color: #000000;">p</span> <span style="color: #008080;">then</span> <span style="color: #008080;">exit</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #000000;">hfactors</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">prepend</span><span style="color: #0000FF;">(</span><span style="color: #000000;">hfactors</span><span style="color: #0000FF;">,</span><span style="color: #000000;">hfactor</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #000000;">p</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #000000;">lfactors</span> <span style="color: #0000FF;">&</span> <span style="color: #000000;">hfactors</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
<!--
|
||||
if include1!=0 then
|
||||
lfactors = {1}
|
||||
if n!=1 and include1=1 then
|
||||
hfactors = {n}
|
||||
end if
|
||||
end if
|
||||
while p<=lim do
|
||||
if remainder(n,p)=0 then
|
||||
lfactors = append(lfactors,p)
|
||||
hfactor = n/p
|
||||
if hfactor=p then exit end if
|
||||
hfactors = prepend(hfactors,hfactor)
|
||||
end if
|
||||
p += 1
|
||||
end while
|
||||
return lfactors & hfactors
|
||||
end function
|
||||
|
|
|
|||
|
|
@ -1,20 +1,18 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">to</span> <span style="color: #000000;">10</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d: %v\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">factors</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)})</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
for i=0 to 10 do
|
||||
printf(1,"%d: %v\n",{i,factors(i,-1)})
|
||||
end for
|
||||
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">candidates</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">maxd</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">20000</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">k</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">factors</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">))</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">k</span><span style="color: #0000FF;">>=</span><span style="color: #000000;">maxd</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">k</span><span style="color: #0000FF;">=</span><span style="color: #000000;">maxd</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #000000;">candidates</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">i</span>
|
||||
<span style="color: #008080;">else</span>
|
||||
<span style="color: #000000;">candidates</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">i</span><span style="color: #0000FF;">}</span>
|
||||
<span style="color: #000000;">maxd</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">k</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d divisors: %v\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">maxd</span><span style="color: #0000FF;">,</span><span style="color: #000000;">candidates</span><span style="color: #0000FF;">})</span>
|
||||
<!--
|
||||
sequence candidates = {}
|
||||
integer maxd = 0
|
||||
for i=1 to 20000 do
|
||||
integer k = length(factors(i,-1))
|
||||
if k>=maxd then
|
||||
if k=maxd then
|
||||
candidates &= i
|
||||
else
|
||||
candidates = {i}
|
||||
maxd = k
|
||||
end if
|
||||
end if
|
||||
end for
|
||||
printf(1,"%d divisors: %v\n", {maxd,candidates})
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
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)"
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
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)"
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
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)"
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
-- 8 May 2025
|
||||
include Settings
|
||||
-- 24 Aug 2025
|
||||
include Setting
|
||||
numeric digits 30
|
||||
|
||||
call Time('r')
|
||||
|
|
@ -56,7 +56,4 @@ end
|
|||
say
|
||||
return
|
||||
|
||||
include Sequences
|
||||
include Functions
|
||||
include Special
|
||||
include Abend
|
||||
include Math
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
ADx ← |1 ⨬(◴⊂⊂⊃(⊙∘|/⊂⊞×)\×°□⊙ADx°⊂|[1])=0⧻.
|
||||
ADs ← ⊏⊸⍏ADx⊕□⊸⊛°/× # All divisors including 1, n.
|
||||
ADx ← |1 ⨬(◴⊂⊂⊃(⊙∘|/⊂⊞×)\×°□⊙ADx°⊂|[1])=0⊸⧻
|
||||
ADs ← ⍆ADx⊕□⊸⊛°/× # All divisors including 1, n.
|
||||
PDs ← ↘¯1ADs # Proper Divisors.
|
||||
≡(□PDs)+1⇡10 # Proper Divisors of 1 to 10.
|
||||
⟜(▽=)/↥.≡(⧻PDs).+1⇡2e4 # Numbers below 20k with most PDs.
|
||||
⟜(▽=)⊸/↥⊸≡(⧻PDs)+1⇡2e4 # Numbers below 20k with most PDs.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue