Aliquot sequence classifications: Difference between revisions

m
syntax highlighting fixup automation
(Aliquot sequence classifications in BASIC256)
m (syntax highlighting fixup automation)
Line 35:
{{trans|Python}}
 
<langsyntaxhighlight lang=11l>F pdsum(n)
R sum((1 .. (n + 1) I/ 2).filter(x -> @n % x == 0 & @n != x))
 
Line 72:
L(n) [11, 12, 28, 496, 220, 1184, 12496, 1264460, 790, 909, 562, 1064, 1488]
V (cls, seq) = aliquot(n)
print(‘#.: #.’.format(cls, seq))</langsyntaxhighlight>
 
{{out}}
Line 103:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits <br> or android 64 bits with application Termux }}
<langsyntaxhighlight lang=AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B or android 64 bits */
/* program aliquotSeq64.s */
Line 660:
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
</lang>
<pre>
Program 64 bits start
Line 691:
=={{header|ALGOL 68}}==
Assumes LONG INT is at least 64 bits, as in Algol 68G.
<langsyntaxhighlight lang=algol68>BEGIN
# aliquot sequence classification #
# maximum sequence length we consider #
Line 796:
print( ( newline ) )
OD
END</langsyntaxhighlight>
{{out}}
<pre>
Line 827:
=={{header|AppleScript}}==
 
<langsyntaxhighlight lang=applescript>on aliquotSum(n)
if (n < 2) then return 0
set sum to 1
Line 895:
set output to output as text
set AppleScript's text item delimiters to astid
return output</langsyntaxhighlight>
 
{{output}}
<langsyntaxhighlight lang=applescript>"
1: terminating 1, 0
2: terminating 2, 1, 0
Line 922:
1064: cyclic 1064, 1336, 1184, 1210
1488: non-terminating 1488, 2480, 3472, 4464, 8432, 9424, 10416, 21328, 22320, 55056, 95728, 96720, 236592, 459792, 881392, 882384
1.535571778608E+13: non-terminating 1.535571778608E+13, 4.453466360112E+13, 1.449400874645E+14"</langsyntaxhighlight>
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi <br> or android 32 bits with application Termux}}
<langsyntaxhighlight lang=ARM Assembly>
/* ARM assembly Raspberry PI */
/* program aliquotSeq.s */
Line 1,470:
.include "../affichage.inc"
 
</syntaxhighlight>
</lang>
<pre>
Program start
Line 1,500:
=={{header|AWK}}==
 
<langsyntaxhighlight lang=awk>
#!/bin/gawk -f
function sumprop(num, i,sum,root) {
Line 1,568:
}
 
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,601:
=={{header|BASIC256}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight lang=BASIC256># Rosetta Code problem: http://rosettacode.org/wiki/Aliquot_sequence_classifications
# by Jjuanhdez, 06/2022
 
Line 1,652:
next element
if clase = 0 then print " non-terminating"
end subroutine</langsyntaxhighlight>
 
=={{header|C}}==
Line 1,658:
===Brute Force===
The following implementation is a brute force method which takes a very, very long time for 15355717786080. To be fair to C, that's also true for many of the other implementations on this page which also implement the brute force method. See the next implementation for the best solution.
<syntaxhighlight lang=C>
<lang C>
#include<stdlib.h>
#include<string.h>
Line 1,730:
return 0;
}
</syntaxhighlight>
</lang>
Input file, you can include 15355717786080 or similar numbers in this list but be prepared to wait for a very, very long time.:
<pre>
Line 1,791:
===Number Theoretic===
The following implementation, based on Number Theory, is the best solution for such a problem. All cases are handled, including 15355717786080, with all the numbers being processed and the output written to console practically instantaneously. The above brute force implementation is the original one and it remains to serve as a comparison of the phenomenal difference the right approach can make to a problem.
<syntaxhighlight lang=C>
<lang C>
#include<string.h>
#include<stdlib.h>
Line 1,893:
return 0;
}
</syntaxhighlight>
</lang>
Input file, to emphasize the effectiveness of this approach, the last number in the file is 153557177860800, 10 times the special case mentioned in the task.
<pre>
Line 1,960:
=={{header|C++}}==
This one follows the trail blazed by the "Number Theoretic" C example above.
<langsyntaxhighlight lang=cpp>#include <cstdint>
#include <iostream>
#include <string>
Line 2,029:
classify_aliquot_sequence(153557177860800);
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 2,062:
=={{header|CLU}}==
{{trans|C++}}
<langsyntaxhighlight lang=clu>% This program uses the 'bigint' cluster from PCLU's 'misc.lib'
 
% Remove leading and trailing whitespace (bigint$unparse adds a lot)
Line 2,157:
classify_aliquot_sequence(bigint$parse("15355717786080"))
classify_aliquot_sequence(bigint$parse("153557177860800"))
end start_up</langsyntaxhighlight>
{{out}}
<pre>1: terminating, sequence: 1 0
Line 2,187:
=={{header|Common Lisp}}==
Uses the Lisp function '''proper-divisors-recursive''' from [[Proper_divisors#Common_Lisp|Task:Proper Divisors]].
<langsyntaxhighlight lang=lisp>(defparameter *nlimit* 16)
(defparameter *klimit* (expt 2 47))
(defparameter *asht* (make-hash-table))
Line 2,253:
(aliquot (+ k 1)))
(dolist (k '(11 12 28 496 220 1184 12496 1264460 790 909 562 1064 1488 15355717786080))
(aliquot k)))</langsyntaxhighlight>
{{out}}
<pre>CL-USER(45): (main)
Line 2,286:
=={{header|D}}==
{{trans|Python}}
<langsyntaxhighlight lang=d>import std.stdio, std.range, std.algorithm, std.typecons, std.conv;
 
auto properDivisors(in ulong n) pure nothrow @safe /*@nogc*/ {
Line 2,336:
790, 909, 562, 1064, 1488])
writefln("%s: %s", n.aliquot[]);
}</langsyntaxhighlight>
{{out}}
<pre>Terminating: [1, 0]
Line 2,364:
 
=={{header|EchoLisp}}==
<langsyntaxhighlight lang=scheme>
;; implementation of Floyd algorithm to find cycles in a graph
;; see Wikipedia https://en.wikipedia.org/wiki/Cycle_detection
Line 2,419:
(when (= x0 starter) (set! end starter)))
(writeln ...))
</syntaxhighlight>
</lang>
{{out}}
<langsyntaxhighlight lang=scheme>
(lib 'math)
(lib 'bigint)
Line 2,461:
1000 terminating
1000 1340 1516 1144 1376 1396 1054 674 340 416 466 236 184 176 196 203 37 1 0 0 ...
</syntaxhighlight>
</lang>
 
=={{header|Elixir}}==
{{trans|Ruby}}
<langsyntaxhighlight lang=elixir>defmodule Proper do
def divisors(1), do: []
def divisors(n), do: [1 | divisors(2,n,:math.sqrt(n))] |> Enum.sort
Line 2,514:
if n<10000000, do: :io.fwrite("~7w:~21s: ~p~n", [n, msg, s]),
else: :io.fwrite("~w: ~s: ~p~n", [n, msg, s])
end)</langsyntaxhighlight>
 
{{out}}
Line 2,550:
=={{header|Factor}}==
For convenience, the term that caused termination is always included in the output sequence.
<langsyntaxhighlight lang=factor>USING: combinators combinators.short-circuit formatting kernel
literals locals math math.functions math.primes.factors
math.ranges namespaces pair-rocket sequences sets ;
Line 2,603:
10 [1,b] test-cases append [ .classify ] each ;
 
MAIN: main</langsyntaxhighlight>
{{out}}
<pre>
Line 2,667:
A more flexible syntax (such as Algol's) would enable the double scan of the TRAIL array to be avoided, as in if TRAIL[I:=MinLoc(Abs(TRAIL(1:L) - SF))] = SF then... That is, find the first index of array TRAIL such that ABS(TRAIL(1:L) - SF) is minimal, save that index in I, then access that element of TRAIL and test if it is equal to SF. The INDEX function could be use to find the first match, except that it is defined only for character variables. Alternatively, use an explicit DO-loop to search for equality, thus not employing fancy syntax, and not having to wonder if the ANY function will stop on the first match rather than wastefully continue the testing for all array elements. The modern style in manual writing is to employ vaguely general talk about arrays and omit specific details.
 
<langsyntaxhighlight lang=Fortran>
MODULE FACTORSTUFF !This protocol evades the need for multiple parameters, or COMMON, or one shapeless main line...
Concocted by R.N.McLean, MMXV.
Line 2,791:
END DO
END !Done.
</syntaxhighlight>
</lang>
 
=={{header|FreeBASIC}}==
{{trans|C}}
<langsyntaxhighlight lang=freebasic>function raiseTo( bas as ulongint, power as ulongint ) as ulongint
dim as ulongint result = 1, i
for i = 1 to power
Line 2,873:
for n as ubyte = 0 to 22
aliquotClassifier(nums(n))
next n</langsyntaxhighlight>
 
=={{header|Go}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang=go>package main
 
import (
Line 2,985:
seq, aliquot := classifySequence(k)
fmt.Printf("%d: %-15s %s\n", k, aliquot, joinWithCommas(seq))
}</langsyntaxhighlight>
 
{{out}}
Line 3,020:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang=Haskell>divisors :: (Integral a) => a -> [a]
divisors n = filter ((0 ==) . (n `mod`)) [1 .. (n `div` 2)]
 
Line 3,060:
let cls n = let ali = take 16 $ aliquot n in (classify ali, ali)
mapM_ (print . cls) $ [1..10] ++
[11, 12, 28, 496, 220, 1184, 12496, 1264460, 790, 909, 562, 1064, 1488]</langsyntaxhighlight>
{{out}}
<pre>(Terminating,[1,0])
Line 3,088:
=={{header|J}}==
Implementation:
<langsyntaxhighlight lang=J>proper_divisors=: [: */@>@}:@,@{ [: (^ i.@>:)&.>/ 2 p: x:
aliquot=: +/@proper_divisors ::0:
rc_aliquot_sequence=: aliquot^:(i.16)&>
Line 3,102:
end.
)
rc_display_aliquot_sequence=: (rc_classify,' ',":)@:rc_aliquot_sequence</langsyntaxhighlight>
 
Task example:
<langsyntaxhighlight lang=J> rc_display_aliquot_sequence&> >: i.10
terminate 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
terminate 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Line 3,131:
cyclic 1064 1336 1184 1210 1184 1210 1184 1210 1184 1210 1184 1210 1184 1210 1184 1210
non-terminating 1488 2480 3472 4464 8432 9424 10416 21328 22320 55056 95728 96720 236592 459792 881392 882384
non-terminating 15355717786080 44534663601120 144940087464480 471714103310688 1130798979186912 2688948041357088 6050151708497568 13613157922639968 35513546724070632 74727605255142168 162658586225561832 353930992506879768 642678347124409032 1125102611548462968 1977286128289819992 3415126495450394808</langsyntaxhighlight>
 
=={{header|Java}}==
Translation of [[Aliquot_sequence_classifications#Python|Python]] via [[Aliquot_sequence_classifications#D|D]]
{{works with|Java|8}}
<langsyntaxhighlight lang=java>import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Line 3,199:
Arrays.stream(arr).forEach(n -> aliquot(n, 16, 1L << 47));
}
}</langsyntaxhighlight>
 
<pre>Terminating: [1, 0]
Line 3,229:
=={{header|jq}}==
{{works with|jq|1.4}}
<langsyntaxhighlight lang=jq># "until" is available in more recent versions of jq
# than jq 1.4
def until(cond; next):
Line 3,287:
790, 909, 562, 1064, 1488, 15355717786080) | pp);
task</langsyntaxhighlight>
{{out}}
<langsyntaxhighlight lang=sh>$ jq -n -r -f aliquot.jq
1: terminating: [1,0]
2: terminating: [2,1,0]
Line 3,314:
1064: cyclic back to 1184: [1064,1336,1184,1210]
1488: non-terminating: [1488,2480,3472,4464,8432,9424,10416,21328,22320,55056,95728,96720,236592,459792,881392,882384]
15355717786080: non-terminating: [15355717786080,44534663601120]</langsyntaxhighlight>
 
=={{header|Julia}}==
'''Core Function'''
<langsyntaxhighlight lang=Julia>
function aliquotclassifier{T<:Integer}(n::T)
a = T[n]
Line 3,343:
return ("Non-terminating", a)
end
</syntaxhighlight>
</lang>
 
'''Supporting Functions'''
<langsyntaxhighlight lang=Julia>
function pcontrib{T<:Integer}(p::T, a::T)
n = one(T)
Line 3,364:
dsum -= n
end
</syntaxhighlight>
</lang>
 
'''Main'''
<langsyntaxhighlight lang=Julia>using Printf
 
println("Classification Tests:")
Line 3,375:
println(@sprintf("%8d => ", i), @sprintf("%16s, ", class), a)
end
</syntaxhighlight>
</lang>
 
{{out}}
Line 3,406:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang=scala>// version 1.1.3
 
data class Classification(val sequence: List<Long>, val aliquot: String)
Line 3,467:
val (seq, aliquot) = classifySequence(k)
println("$k: ${aliquot.padEnd(15)} $seq")
}</langsyntaxhighlight>
 
{{out}}
Line 3,517:
 
There are no sociable sequences.
<syntaxhighlight lang=lb>
<lang lb>
print "ROSETTA CODE - Aliquot sequence classifications"
[Start]
Line 3,562:
next
end function
</syntaxhighlight>
</lang>
 
{{out}}
Line 3,631:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight lang=Mathematica>seq[n_] :=
NestList[If[# == 0, 0,
DivisorSum[#, # &, Function[div, div != #]]] &, n, 16];
Line 3,649:
Print[{#, class[seq[#]], notate[seq[#]] /. {0} -> 0}] & /@ {1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 28, 496, 220, 1184, 12496, 1264460, 790, 909,
562, 1064, 1488, 15355717786080};</langsyntaxhighlight>
{{out}}
<pre>{1, Terminating, {1, 0}}
Line 3,677:
 
=={{header|Nim}}==
<langsyntaxhighlight lang=Nim>
import math
import strformat
Line 3,778:
echo ""
echo fmt"Processed in {(getTime() - t0).inMilliseconds} ms."
</syntaxhighlight>
</lang>
 
{{out}}
Line 3,813:
=={{header|Oforth}}==
 
<langsyntaxhighlight lang=oforth>import: mapping
import: quicksort
import: math
Line 3,849:
]
"non-terminating"
;</langsyntaxhighlight>
 
{{out}}
Line 3,889:
=={{header|PARI/GP}}==
Define function aliquot(). Works with recent versions of PARI/GP >= 2.8:
<langsyntaxhighlight lang=parigp>aliquot(x) =
{
my (L = List(x), M = Map(Mat([x,1])), k, m = "non-term.", n = x);
Line 3,906:
);
printf("%16d: %10s, %s\n", x, m, Vec(L));
}</langsyntaxhighlight>
 
Output:
Line 3,938:
=={{header|Perl}}==
{{libheader|ntheory}}
<langsyntaxhighlight lang=perl>use ntheory qw/divisor_sum/;
 
sub aliquot {
Line 3,973:
my($class, @seq) = aliquot($n);
printf "%14d %10s [@seq]\n", $n, $class;
}</langsyntaxhighlight>
{{out}}
<pre> 1 terminates [1 0]
Line 4,003:
=={{header|Phix}}==
Translated from the Python example
<!--<langsyntaxhighlight lang=Phix>-->
<span style="color: #008080;">function</span> <span style="color: #000000;">aliquot</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;">sequence</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">n</span><span style="color: #0000FF;">}</span>
Line 4,032:
<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;">"%14d =&gt; %15s, {%s}\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">n</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">],</span><span style="color: #000000;">classification</span><span style="color: #0000FF;">,</span><span style="color: #000000;">dseq</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 4,063:
=={{header|Picat}}==
{{trans|C++}}
<langsyntaxhighlight lang=Picat>divisor_sum(N) = R =>
Total = 1,
Power = 2,
Line 4,119:
nl
end.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 4,150:
{{works with|PowerShell|4.0}}<br/>
<b>Simple</b>
<langsyntaxhighlight lang=powershell>function Get-NextAliquot ( [int]$X )
{
If ( $X -gt 1 )
Line 4,183:
(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 ) ) }</langsyntaxhighlight>
<b>Optimized</b>
<langsyntaxhighlight lang=powershell>function Get-NextAliquot ( [int]$X )
{
If ( $X -gt 1 )
Line 4,247:
(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 ) ) }</langsyntaxhighlight>
{{out}}
<pre>1 is terminating
Line 4,274:
 
===Version 3.0===
<langsyntaxhighlight lang=PowerShell>
function Get-Aliquot
{
Line 4,365:
}
}
</syntaxhighlight>
</lang>
<langsyntaxhighlight lang=PowerShell>
$oneToTen = 1..10 | Get-Aliquot
$selected = 11, 12, 28, 496, 220, 1184, 12496, 1264460, 790, 909, 562, 1064, 1488 | Get-Aliquot
Line 4,372:
$numbers = $oneToTen, $selected
$numbers
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 4,405:
{{trans|C++}}
{{works with|SWI Prolog}}
<langsyntaxhighlight lang=prolog>% See https://en.wikipedia.org/wiki/Divisor_function
divisor_sum(N, Total):-
divisor_sum_prime(N, 2, 2, Total1, 1, N1),
Line 4,473:
write_aliquot_sequence(N, Sequence, Class),
fail.
main.</langsyntaxhighlight>
 
{{out}}
Line 4,505:
Importing [[Proper_divisors#Python:_From_prime_factors|Proper divisors from prime factors]]:
 
<langsyntaxhighlight lang=python>from proper_divisors import proper_divs
from functools import lru_cache
 
Line 4,545:
print()
for n in [11, 12, 28, 496, 220, 1184, 12496, 1264460, 790, 909, 562, 1064, 1488, 15355717786080]:
print('%s: %r' % aliquot(n))</langsyntaxhighlight>
 
{{out}}
Line 4,577:
{{works with|QBasic|1.1}}
{{trans|Liberty BASIC}}
<langsyntaxhighlight lang=QBasic>DECLARE FUNCTION PDtotal! (n!)
DECLARE SUB PrintAliquotClassifier (K!)
CLS
Line 4,632:
IF clase = 0 THEN COLOR 12: PRINT " non-terminating"
COLOR 7
END SUB</langsyntaxhighlight>
{{out}}
<pre>Number 1 : 0 Terminating
Line 4,663:
'''fold-divisors''' is used from [[Proper_divisors#Racket]], but for the truly big numbers, we use divisors from math/number-theory.
 
<langsyntaxhighlight lang=racket>#lang racket
(require "proper-divisors.rkt" math/number-theory)
 
Line 4,715:
 
(for ((i (in-list '(11 12 28 496 220 1184 12496 1264460 790 909 562 1064 1488 15355717786080))))
(report-aliquot-sequence-class i))</langsyntaxhighlight>
 
{{out}}
Line 4,747:
(formerly Perl 6)
{{works with|rakudo|2018.10}}
<langsyntaxhighlight lang=perl6>sub propdivsum (\x) {
my @l = x > 1;
(2 .. x.sqrt.floor).map: -> \d {
Line 4,780:
11, 12, 28, 496, 220, 1184, 12496, 1264460,
790, 909, 562, 1064, 1488,
15355717786080;</langsyntaxhighlight>
{{out}}
<pre>1 terminating [1]
Line 4,818:
 
Both of the above limitations are imposed by this Rosetta Code task's restriction requirements: &nbsp; ''For the purposes of this task, ···''.
<langsyntaxhighlight lang=rexx>/*REXX program classifies various positive integers for types of aliquot sequences. */
parse arg low high $L /*obtain optional arguments from the CL*/
high= word(high low 10,1); low= word(low 1,1) /*obtain the LOW and HIGH (range). */
Line 4,880:
if j*j==x then s= s + j /*Was X a square? If so, add √ X */
#.x= s /*memoize division sum for argument X.*/
return s /*return " " " " " */</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
(Shown at three-quarter size.)
Line 4,924:
 
=={{header|Ring}}==
<langsyntaxhighlight lang=ring>
# Project : Aliquot sequence classnifications
 
Line 5,003:
next
return pdtotal
</syntaxhighlight>
</lang>
Output:
<pre>
Line 5,074:
{{trans|Python}}
 
<langsyntaxhighlight lang=ruby>def aliquot(n, maxlen=16, maxterm=2**47)
return "terminating", [0] if n == 0
s = []
Line 5,102:
for n in [11, 12, 28, 496, 220, 1184, 12496, 1264460, 790, 909, 562, 1064, 1488, 15355717786080]
puts "%20s: %p" % aliquot(n)
end</langsyntaxhighlight>
 
{{out}}
Line 5,134:
 
=={{header|Rust}}==
<langsyntaxhighlight lang=rust>#[derive(Debug)]
enum AliquotType { Terminating, Perfect, Amicable, Sociable, Aspiring, Cyclic, NonTerminating }
 
Line 5,178:
println!("{} {:?}", num, classify_aliquot(*num));
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 5,208:
=={{header|Scala}}==
Put [[proper_divisors#Scala]] the full /Proper divisors for big (long) numbers/ section to the beginning:
<langsyntaxhighlight lang=Scala>def createAliquotSeq(n: Long, step: Int, list: List[Long]): (String, List[Long]) = {
val sum = properDivisors(n).sum
if (sum == 0) ("terminate", list ::: List(sum))
Line 5,227:
val result = numbers.map(i => createAliquotSeq(i, 0, List(i)))
 
result foreach { v => println(f"${v._2.head}%14d ${v._1}%10s [${v._2 mkString " "}]" ) }</langsyntaxhighlight>
 
{{out}}
Line 5,257:
=={{header|Swift}}==
 
<langsyntaxhighlight lang=swift>extension BinaryInteger {
@inlinable
public func factors(sorted: Bool = true) -> [Self] {
Line 5,323:
print()
 
print("\(15355717786080): \(classifySequence(k: 15355717786080))")</langsyntaxhighlight>
 
{{out}}
Line 5,358:
This solution creates an iterator from a coroutine to generate aliquot sequences. al_classify uses a "RESULT" exception to achieve some unusual control flow.
 
<langsyntaxhighlight lang=Tcl>proc ProperDivisors {n} {
if {$n == 1} {return 0}
set divs 1
Line 5,430:
puts [time {
puts [format "%8d -> %-16s : %s" $i {*}[al_classify $i]]
}]</langsyntaxhighlight>
 
{{out}}
Line 5,464:
 
=={{header|VBA}}==
<langsyntaxhighlight lang=vb>Option Explicit
 
Private Type Aliquot
Line 5,530:
SumPDiv = t
End Function
</syntaxhighlight>
</lang>
 
{{out}}
Line 5,560:
=={{header|Vlang}}==
{{trans|Go}}
<langsyntaxhighlight lang=vlang>import math
const threshold = u64(1) << 47
Line 5,664:
seq, aliquot := classify_sequence(k)
println("$k: ${aliquot:-15} $seq")
}</langsyntaxhighlight>
 
{{out}}
Line 5,703:
{{libheader|Wren-math}}
{{libheader|Wren-seq}}
<langsyntaxhighlight lang=ecmascript>import "/fmt" for Conv, Fmt
import "/math" for Int, Nums
import "/seq" for Lst
Line 5,755:
var c = classifySequence.call(k)
var seq = c.seq.map { |i| Conv.dec(i) }.toList // ensure 15 digit integer is printed in full
System.print("%(k): %(Fmt.s(-15, c.aliquot)) %(seq)")</langsyntaxhighlight>
 
{{out}}
Line 5,791:
=={{header|Yabasic}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight lang=Yabasic>// Rosetta Code problem: http://rosettacode.org/wiki/Aliquot_sequence_classifications
// by Galileo, 05/2022
 
Line 5,851:
if not n break
alliquot(n)
loop</langsyntaxhighlight>
{{out}}
<pre>Integer: 1, Type: Terminating, Series: 1
Line 5,879:
 
=={{header|zkl}}==
<langsyntaxhighlight lang=zkl>fcn properDivs(n){ [1.. (n + 1)/2 + 1].filter('wrap(x){ n%x==0 and n!=x }) }
fcn aliquot(k){ //-->Walker
Walker(fcn(rk){ k:=rk.value; if(k)rk.set(properDivs(k).sum()); k }.fp(Ref(k)))
}(10).walk(15).println();</langsyntaxhighlight>
Or, refactoring to remove saving the intermediate divisors (and adding white space):
<langsyntaxhighlight lang=zkl>fcn aliquot(k){ //-->Walker
Walker(fcn(rk){
k:=rk.value;
Line 5,892:
k
}.fp(Ref(k)))
}(10).walk(15).println();</langsyntaxhighlight>
<langsyntaxhighlight lang=zkl>fcn classify(k){
const MAX=(2).pow(47); // 140737488355328
ak,aks:=aliquot(k), ak.walk(16);
Line 5,914:
else "non-terminating" )
+ " " + aks.filter();
}</langsyntaxhighlight>
<langsyntaxhighlight lang=zkl>[1..10].pump(fcn(k){ "%6d is %s".fmt(k,classify(k)).println() });
T(11,12,28,496,220,1184,12496,1264460,790,909,562,1064,1488)
.pump(fcn(k){ "%6d is %s".fmt(k,classify(k)).println() });</langsyntaxhighlight>
{{out}}
<pre>
Line 5,950:
{{trans|AWK}}
This program is correct. However, a bug in the ROM of the ZX Spectrum makes the number 909 of an erroneous result. However, the same program running on Sam BASIC (a superset of Sinclair BASIC that ran on the computer Sam Coupé) provides the correct results.
<langsyntaxhighlight lang=zxbasic>10 PRINT "Number classification sequence"
20 INPUT "Enter a number (0 to end): ";k: IF k>0 THEN GO SUB 2000: PRINT k;" ";s$: GO TO 20
40 STOP
Line 5,990:
2320 NEXT t
2330 LET s$="non-terminating (after 16 terms)"+s$
2340 RETURN</langsyntaxhighlight>
{{out}}
<pre>Number classification sequence
10,327

edits