Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -0,0 +1,35 @@
|
|||
def sum_proper_divisors (n)
|
||||
z = n.class.zero
|
||||
(z+1..n//2).sum(z) {|i| n % i == 0 ? i : 0 }
|
||||
end
|
||||
|
||||
def aliquot (n)
|
||||
seq = [n]
|
||||
limit = 2_i64**47
|
||||
15.times do
|
||||
n = sum_proper_divisors(n)
|
||||
case n
|
||||
when 0 then return { "terminating", seq << n }
|
||||
when .>(limit) then return { "non-terminating", seq << n }
|
||||
when seq[0] then return { case seq.size
|
||||
when 1 then "perfect"
|
||||
when 2 then "amicable"
|
||||
else "sociable"
|
||||
end, seq }
|
||||
when seq.last then return { "aspiring", seq }
|
||||
when .in?(seq) then return { "cyclic", seq << n }
|
||||
end
|
||||
seq << n
|
||||
end
|
||||
{ "non-terminating", seq }
|
||||
end
|
||||
|
||||
(1..10).each do |i|
|
||||
kind, seq = aliquot(i)
|
||||
puts "%s: %s" % { kind, seq }
|
||||
end
|
||||
puts
|
||||
[11, 12, 28, 496, 220, 1184, 12496, 1264460, 790, 909, 562, 1064, 1488].each do |i|
|
||||
kind, seq = aliquot(i)
|
||||
puts "%s: %s" % { kind, seq }
|
||||
end
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
local int = require "int"
|
||||
local fmt = require "fmt"
|
||||
require "table2"
|
||||
|
||||
$define THRESHOLD = 1 << 47
|
||||
|
||||
class classification
|
||||
function __construct(public seq, public aliquot) end
|
||||
end
|
||||
|
||||
local function classify_sequence(k)
|
||||
assert(k > 0, "K must be positive")
|
||||
local last = k
|
||||
local seq = {k}
|
||||
while true do
|
||||
last = int.divisors(last, true):sum()
|
||||
seq:insert(last)
|
||||
local n = #seq
|
||||
local aliquot = ""
|
||||
if last == 0 then
|
||||
aliquot = "Terminating"
|
||||
elseif n == 2 and last == k then
|
||||
aliquot = "Perfect"
|
||||
elseif n == 3 and last == k then
|
||||
aliquot = "Amicable"
|
||||
elseif n >= 4 and last == k then
|
||||
aliquot = $"Sociable[{n - 1}]"
|
||||
elseif last == seq[n - 1] then
|
||||
aliquot = "Aspiring"
|
||||
elseif n > 3 and (last in seq:slice(2, n - 2)) then
|
||||
local ix = seq:findindex(|e| -> e == last) ?? -1
|
||||
aliquot = $"Cyclic[{n - ix}]"
|
||||
elseif n == 16 or last > THRESHOLD then
|
||||
aliquot = "Non-terminating"
|
||||
end
|
||||
if aliquot != "" then return new classification(seq, aliquot) end
|
||||
end
|
||||
end
|
||||
|
||||
print("Aliquot classifications - periods for Sociable/Cyclic in square brackets:\n")
|
||||
for k = 1, 10 do
|
||||
local c = classify_sequence(k)
|
||||
fmt.print("%2d: %-15s %,s", k, c.aliquot, c.seq)
|
||||
end
|
||||
|
||||
print()
|
||||
local a = {11, 12, 28, 496, 220, 1184, 12496, 1264460, 790, 909, 562, 1064, 1488}
|
||||
for a as k do
|
||||
local c = classify_sequence(k)
|
||||
fmt.print("%7d: %-15s %,s", k, c.aliquot, c.seq)
|
||||
end
|
||||
|
||||
print()
|
||||
local k = 15355717786080
|
||||
local c = classify_sequence(k)
|
||||
fmt.print("%d: %-15s %,s", k, c.aliquot, c.seq)
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
function Get-NextAliquot ( [int]$X )
|
||||
{
|
||||
If ( $X -gt 1 )
|
||||
{
|
||||
$NextAliquot = 0
|
||||
(1..($X/2)).Where{ $x % $_ -eq 0 }.ForEach{ $NextAliquot += $_ }.Where{ $_ }
|
||||
return $NextAliquot
|
||||
}
|
||||
}
|
||||
|
||||
function Get-AliquotSequence ( [int]$K, [int]$N )
|
||||
{
|
||||
$X = $K
|
||||
$X
|
||||
(1..($N-1)).ForEach{ $X = Get-NextAliquot $X; $X }
|
||||
}
|
||||
|
||||
function Classify-AlliquotSequence ( [int[]]$Sequence )
|
||||
{
|
||||
$K = $Sequence[0]
|
||||
$LastN = $Sequence.Count
|
||||
If ( $Sequence[-1] -eq 0 ) { return "terminating" }
|
||||
If ( $Sequence[-1] -eq 1 ) { return "terminating" }
|
||||
If ( $Sequence[1] -eq $K ) { return "perfect" }
|
||||
If ( $Sequence[2] -eq $K ) { return "amicable" }
|
||||
If ( $Sequence[3..($Sequence.Count-1)] -contains $K ) { return "sociable" }
|
||||
If ( $Sequence[-1] -eq $Sequence[-2] ) { return "aspiring" }
|
||||
If ( $Sequence.Count -gt ( $Sequence | Select -Unique ).Count ) { return "cyclic" }
|
||||
return "non-terminating and non-repeating through N = $($Sequence.Count)"
|
||||
}
|
||||
|
||||
(1..10).ForEach{ [string]$_ + " is " + ( Classify-AlliquotSequence -Sequence ( Get-AliquotSequence -K $_ -N 16 ) ) }
|
||||
|
||||
( 11, 12, 28, 496, 220, 1184, 790, 909, 562, 1064, 1488 ).ForEach{ [string]$_ + " is " + ( Classify-AlliquotSequence -Sequence ( Get-AliquotSequence -K $_ -N 16 ) ) }
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
function Get-NextAliquot ( [int]$X )
|
||||
{
|
||||
If ( $X -gt 1 )
|
||||
{
|
||||
$NextAliquot = 1
|
||||
If ( $X -gt 2 )
|
||||
{
|
||||
$XSquareRoot = [math]::Sqrt( $X )
|
||||
|
||||
(2..$XSquareRoot).Where{ $X % $_ -eq 0 }.ForEach{ $NextAliquot += $_ + $x / $_ }
|
||||
|
||||
If ( $XSquareRoot % 1 -eq 0 ) { $NextAliquot -= $XSquareRoot }
|
||||
}
|
||||
return $NextAliquot
|
||||
}
|
||||
}
|
||||
|
||||
function Get-AliquotSequence ( [int]$K, [int]$N )
|
||||
{
|
||||
$X = $K
|
||||
$X
|
||||
$i = 1
|
||||
While ( $X -and $i -lt $N )
|
||||
{
|
||||
$i++
|
||||
$Next = Get-NextAliquot $X
|
||||
If ( $Next )
|
||||
{
|
||||
If ( $X -eq $Next )
|
||||
{
|
||||
($i..$N).ForEach{ $X }
|
||||
$i = $N
|
||||
}
|
||||
Else
|
||||
{
|
||||
$X = $Next
|
||||
$X
|
||||
}
|
||||
}
|
||||
Else
|
||||
{
|
||||
$i = $N
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Classify-AlliquotSequence ( [int[]]$Sequence )
|
||||
{
|
||||
$K = $Sequence[0]
|
||||
$LastN = $Sequence.Count
|
||||
If ( $Sequence[-1] -eq 0 ) { return "terminating" }
|
||||
If ( $Sequence[-1] -eq 1 ) { return "terminating" }
|
||||
If ( $Sequence[1] -eq $K ) { return "perfect" }
|
||||
If ( $Sequence[2] -eq $K ) { return "amicable" }
|
||||
If ( $Sequence[3..($Sequence.Count-1)] -contains $K ) { return "sociable" }
|
||||
If ( $Sequence[-1] -eq $Sequence[-2] ) { return "aspiring" }
|
||||
If ( $Sequence.Count -gt ( $Sequence | Select -Unique ).Count ) { return "cyclic" }
|
||||
return "non-terminating and non-repeating through N = $($Sequence.Count)"
|
||||
}
|
||||
|
||||
(1..10).ForEach{ [string]$_ + " is " + ( Classify-AlliquotSequence -Sequence ( Get-AliquotSequence -K $_ -N 16 ) ) }
|
||||
|
||||
( 11, 12, 28, 496, 220, 1184, 12496, 1264460, 790, 909, 562, 1064, 1488 ).ForEach{ [string]$_ + " is " + ( Classify-AlliquotSequence -Sequence ( Get-AliquotSequence -K $_ -N 16 ) ) }
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
function Get-Aliquot
|
||||
{
|
||||
[CmdletBinding()]
|
||||
[OutputType([PScustomObject])]
|
||||
Param
|
||||
(
|
||||
[Parameter(Mandatory=$true,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true)]
|
||||
[int]
|
||||
$InputObject
|
||||
)
|
||||
|
||||
Begin
|
||||
{
|
||||
function Get-NextAliquot ([int]$X)
|
||||
{
|
||||
if ($X -gt 1)
|
||||
{
|
||||
$nextAliquot = 1
|
||||
|
||||
if ($X -gt 2)
|
||||
{
|
||||
$xSquareRoot = [Math]::Sqrt($X)
|
||||
|
||||
2..$xSquareRoot | Where-Object {$X % $_ -eq 0} | ForEach-Object {$nextAliquot += $_ + $x / $_}
|
||||
|
||||
if ($xSquareRoot % 1 -eq 0) {$nextAliquot -= $xSquareRoot}
|
||||
}
|
||||
|
||||
$nextAliquot
|
||||
}
|
||||
}
|
||||
|
||||
function Get-AliquotSequence ([int]$K, [int]$N)
|
||||
{
|
||||
$X = $K
|
||||
$X
|
||||
$i = 1
|
||||
|
||||
while ($X -and $i -lt $N)
|
||||
{
|
||||
$i++
|
||||
$next = Get-NextAliquot $X
|
||||
|
||||
if ($next)
|
||||
{
|
||||
if ($X -eq $next)
|
||||
{
|
||||
$i..$N | ForEach-Object {$X}
|
||||
$i = $N
|
||||
}
|
||||
else
|
||||
{
|
||||
$X = $next
|
||||
$X
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$i = $N
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Classify-AlliquotSequence ([int[]]$Sequence)
|
||||
{
|
||||
$k = $Sequence[0]
|
||||
|
||||
if ($Sequence[-1] -eq 0) {return "terminating"}
|
||||
if ($Sequence[-1] -eq 1) {return "terminating"}
|
||||
if ($Sequence[1] -eq $k) {return "perfect" }
|
||||
if ($Sequence[2] -eq $k) {return "amicable" }
|
||||
if ($Sequence[3..($Sequence.Count-1)] -contains $k) {return "sociable" }
|
||||
if ($Sequence[-1] -eq $Sequence[-2] ) {return "aspiring" }
|
||||
if ($Sequence.Count -gt ($Sequence | Select -Unique).Count ) {return "cyclic" }
|
||||
|
||||
return "non-terminating and non-repeating through N = $($Sequence.Count)"
|
||||
}
|
||||
}
|
||||
Process
|
||||
{
|
||||
$_ | ForEach-Object {
|
||||
[PSCustomObject]@{
|
||||
Number = $_
|
||||
Classification = (Classify-AlliquotSequence -Sequence (Get-AliquotSequence -K $_ -N 16))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
$oneToTen = 1..10 | Get-Aliquot
|
||||
$selected = 11, 12, 28, 496, 220, 1184, 12496, 1264460, 790, 909, 562, 1064, 1488 | Get-Aliquot
|
||||
|
||||
$numbers = $oneToTen, $selected
|
||||
$numbers
|
||||
Loading…
Add table
Add a link
Reference in a new issue