Aliquot sequence classifications: Difference between revisions

→‎{{header|REXX}}: make it ooRexx compatible and readable
(Aliquot sequence classifications in BASIC256)
(→‎{{header|REXX}}: make it ooRexx compatible and readable)
(10 intermediate revisions by 8 users not shown)
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 }}
<syntaxhighlight lang="aarch64 assembly">
<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}}
<syntaxhighlight lang="arm assembly">
<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,599:
</pre>
 
=={{header|BASIC256BASIC}}==
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<langsyntaxhighlight BASIC256lang="basic256"># Rosetta Code problem: http://rosettacode.org/wiki/Aliquot_sequence_classifications
# by Jjuanhdez, 06/2022
 
Line 1,652 ⟶ 1,653:
next element
if clase = 0 then print " non-terminating"
end subroutine</langsyntaxhighlight>
 
=={{header|C}}==
Line 1,658 ⟶ 1,659:
===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 ⟶ 1,731:
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 ⟶ 1,792:
===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 ⟶ 1,894:
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,957 ⟶ 1,958:
336056, 1405725265675144, 1230017019320456, 68719476751
</pre>
 
 
=={{header|C#}}==
{{trans|Java}}
<syntaxhighlight lang="C#">
using System;
using System.Collections.Generic;
using System.Linq;
 
public class AliquotSequenceClassifications
{
private static long ProperDivsSum(long n)
{
return Enumerable.Range(1, (int)(n / 2)).Where(i => n % i == 0).Sum(i => (long)i);
}
 
public static bool Aliquot(long n, int maxLen, long maxTerm)
{
List<long> s = new List<long>(maxLen) {n};
long newN = n;
 
while (s.Count <= maxLen && newN < maxTerm)
{
newN = ProperDivsSum(s.Last());
 
if (s.Contains(newN))
{
if (s[0] == newN)
{
switch (s.Count)
{
case 1:
return Report("Perfect", s);
case 2:
return Report("Amicable", s);
default:
return Report("Sociable of length " + s.Count, s);
}
}
else if (s.Last() == newN)
{
return Report("Aspiring", s);
}
else
{
return Report("Cyclic back to " + newN, s);
}
}
else
{
s.Add(newN);
if (newN == 0)
return Report("Terminating", s);
}
}
 
return Report("Non-terminating", s);
}
 
static bool Report(string msg, List<long> result)
{
Console.WriteLine(msg + ": " + string.Join(", ", result));
return false;
}
 
public static void Main(string[] args)
{
long[] arr = {
11, 12, 28, 496, 220, 1184, 12496, 1264460,
790, 909, 562, 1064, 1488
};
 
Enumerable.Range(1, 10).ToList().ForEach(n => Aliquot(n, 16, 1L << 47));
Console.WriteLine();
foreach (var n in arr)
{
Aliquot(n, 16, 1L << 47);
}
}
}
</syntaxhighlight>
{{out}}
<pre>
Terminating: 1, 0
Terminating: 2, 1, 0
Terminating: 3, 1, 0
Terminating: 4, 3, 1, 0
Terminating: 5, 1, 0
Perfect: 6
Terminating: 7, 1, 0
Terminating: 8, 7, 1, 0
Terminating: 9, 4, 3, 1, 0
Terminating: 10, 8, 7, 1, 0
 
Terminating: 11, 1, 0
Terminating: 12, 16, 15, 9, 4, 3, 1, 0
Perfect: 28
Perfect: 496
Amicable: 220, 284
Amicable: 1184, 1210
Sociable of length 5: 12496, 14288, 15472, 14536, 14264
Sociable of length 4: 1264460, 1547860, 1727636, 1305184
Aspiring: 790, 650, 652, 496
Aspiring: 909, 417, 143, 25, 6
Cyclic back to 284: 562, 284, 220
Cyclic back to 1184: 1064, 1336, 1184, 1210
Non-terminating: 1488, 2480, 3472, 4464, 8432, 9424, 10416, 21328, 22320, 55056, 95728, 96720, 236592, 459792, 881392, 882384, 1474608
 
</pre>
 
 
=={{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 ⟶ 2,140:
classify_aliquot_sequence(153557177860800);
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 2,062 ⟶ 2,173:
=={{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 ⟶ 2,268:
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 ⟶ 2,298:
=={{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 ⟶ 2,364:
(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 ⟶ 2,397:
=={{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 ⟶ 2,447:
790, 909, 562, 1064, 1488])
writefln("%s: %s", n.aliquot[]);
}</langsyntaxhighlight>
{{out}}
<pre>Terminating: [1, 0]
Line 2,362 ⟶ 2,473:
Cyclic back to 1184: [1064, 1336, 1184, 1210]
Non-terminating: [1488, 2480, 3472, 4464, 8432, 9424, 10416, 21328, 22320, 55056, 95728, 96720, 236592, 459792, 881392, 882384, 1474608]</pre>
 
=={{header|EasyLang}}==
{{trans|AWK}}
<syntaxhighlight lang=easylang>
fastfunc sumprop num .
if num = 1
return 0
.
sum = 1
root = sqrt num
i = 2
while i < root
if num mod i = 0
sum += i + num / i
.
i += 1
.
if num mod root = 0
sum += root
.
return sum
.
func$ tostr ar[] .
for v in ar[]
s$ &= " " & v
.
return s$
.
func$ class k .
oldk = k
newk = sumprop oldk
oldk = newk
seq[] &= newk
if newk = 0
return "terminating " & tostr seq[]
.
if newk = k
return "perfect " & tostr seq[]
.
newk = sumprop oldk
oldk = newk
seq[] &= newk
if newk = 0
return "terminating " & tostr seq[]
.
if newk = k
return "amicable " & tostr seq[]
.
for t = 4 to 16
newk = sumprop oldk
seq[] &= newk
if newk = 0
return "terminating " & tostr seq[]
.
if newk = k
return "sociable (period " & t - 1 & ") " & tostr seq[]
.
if newk = oldk
return "aspiring " & tostr seq[]
.
for i to len seq[] - 1
if newk = seq[i]
return "cyclic (at " & newk & ") " & tostr seq[]
.
.
if newk > 140737488355328
return "non-terminating (term > 140737488355328) " & tostr seq[]
.
oldk = newk
.
return "non-terminating (after 16 terms) " & tostr seq[]
.
print "Number classification sequence"
for j = 1 to 12
print j & " " & class j
.
for j in [ 28 496 220 1184 12496 1264460 790 909 562 1064 1488 15355717786080 ]
print j & " " & class j
.
</syntaxhighlight>
 
=={{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 ⟶ 2,610:
(when (= x0 starter) (set! end starter)))
(writeln ...))
</syntaxhighlight>
</lang>
{{out}}
<langsyntaxhighlight lang="scheme">
(lib 'math)
(lib 'bigint)
Line 2,461 ⟶ 2,652:
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 ⟶ 2,705:
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 ⟶ 2,741:
=={{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 ⟶ 2,794:
10 [1,b] test-cases append [ .classify ] each ;
 
MAIN: main</langsyntaxhighlight>
{{out}}
<pre>
Line 2,667 ⟶ 2,858:
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.
 
<syntaxhighlight lang="fortran">
<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 ⟶ 2,982:
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 ⟶ 3,064:
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 ⟶ 3,176:
seq, aliquot := classifySequence(k)
fmt.Printf("%d: %-15s %s\n", k, aliquot, joinWithCommas(seq))
}</langsyntaxhighlight>
 
{{out}}
Line 3,020 ⟶ 3,211:
 
=={{header|Haskell}}==
<langsyntaxhighlight Haskelllang="haskell">divisors :: (Integral a) => a -> [a]
divisors n = filter ((0 ==) . (n `mod`)) [1 .. (n `div` 2)]
 
Line 3,060 ⟶ 3,251:
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 ⟶ 3,279:
=={{header|J}}==
Implementation:
<langsyntaxhighlight Jlang="j">proper_divisors=: [: */@>@}:@,@{ [: (^ i.@>:)&.>/ 2 p: x:
aliquot=: +/@proper_divisors ::0:
rc_aliquot_sequence=: aliquot^:(i.16)&>
Line 3,102 ⟶ 3,293:
end.
)
rc_display_aliquot_sequence=: (rc_classify,' ',":)@:rc_aliquot_sequence</langsyntaxhighlight>
 
Task example:
<langsyntaxhighlight Jlang="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 ⟶ 3,322:
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 ⟶ 3,390:
Arrays.stream(arr).forEach(n -> aliquot(n, 16, 1L << 47));
}
}</langsyntaxhighlight>
 
<pre>Terminating: [1, 0]
Line 3,229 ⟶ 3,420:
=={{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 ⟶ 3,478:
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 ⟶ 3,505:
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'''
<syntaxhighlight lang="julia">
<lang Julia>
function aliquotclassifier{T<:Integer}(n::T)
a = T[n]
Line 3,343 ⟶ 3,534:
return ("Non-terminating", a)
end
</syntaxhighlight>
</lang>
 
'''Supporting Functions'''
<syntaxhighlight lang="julia">
<lang Julia>
function pcontrib{T<:Integer}(p::T, a::T)
n = one(T)
Line 3,364 ⟶ 3,555:
dsum -= n
end
</syntaxhighlight>
</lang>
 
'''Main'''
<langsyntaxhighlight Julialang="julia">using Printf
 
println("Classification Tests:")
Line 3,375 ⟶ 3,566:
println(@sprintf("%8d => ", i), @sprintf("%16s, ", class), a)
end
</syntaxhighlight>
</lang>
 
{{out}}
Line 3,406 ⟶ 3,597:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.1.3
 
data class Classification(val sequence: List<Long>, val aliquot: String)
Line 3,467 ⟶ 3,658:
val (seq, aliquot) = classifySequence(k)
println("$k: ${aliquot.padEnd(15)} $seq")
}</langsyntaxhighlight>
 
{{out}}
Line 3,517 ⟶ 3,708:
 
There are no sociable sequences.
<syntaxhighlight lang="lb">
<lang lb>
print "ROSETTA CODE - Aliquot sequence classifications"
[Start]
Line 3,562 ⟶ 3,753:
next
end function
</syntaxhighlight>
</lang>
 
{{out}}
Line 3,631 ⟶ 3,822:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">seq[n_] :=
NestList[If[# == 0, 0,
DivisorSum[#, # &, Function[div, div != #]]] &, n, 16];
Line 3,649 ⟶ 3,840:
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 ⟶ 3,868:
 
=={{header|Nim}}==
<syntaxhighlight lang="nim">import std/[math, strformat, times]
<lang Nim>
from std/strutils import mathaddSep
import strformat
from strutils import addSep
import times
 
type
 
# Classification categories.
Category {.pure.} = enum
Unknown
Terminating = "terminating"
Line 3,697 ⟶ 3,885:
 
# Aliquot sequence.
AliquotSeq = seq[intint64]
 
const Limit = 2^47 # Limit beyond which the category is considered to be "NonTerminating".
Line 3,703 ⟶ 3,891:
#---------------------------------------------------------------------------------------------------
 
proc sumProperDivisors(n: intint64): intint64 =
## Compute the sum of proper divisors.*
 
if n == 1: return 0
result = 1
for d in 2..sqrt(n.toFloatfloat).int:
if n mod d == 0:
inc result, d
if n div d != d:
inc result, += n div d
 
#---------------------------------------------------------------------------------------------------
 
iterator aliquotSeq(n: intint64): intint64 =
## Yield the elements of the aliquot sequence of "n".
## Stopped if the current value is null or equal to "n".
Line 3,736 ⟶ 3,924:
#---------------------------------------------------------------------------------------------------
 
proc classification(n: intint64): tuple[cat: Category, values: AliquotSeq] =
## Return the category of the aliquot sequence of a number "n" and the sequence itself.
 
Line 3,768 ⟶ 3,956:
for n in 1..10:
let (cat, aseq) = classification(n)
echo fmt"{n:14}: {cat:<20} {aseq}"
 
echo ""
for n in [int64 11, 12, 28, 496, 220, 1184, 12496, 1264460,
790, 909, 562, 1064, 1488, 15355717786080.int]:
let (cat, aseq) = classification(n)
echo fmt"{n:14}: {cat:<20} {aseq}"
Line 3,778 ⟶ 3,966:
echo ""
echo fmt"Processed in {(getTime() - t0).inMilliseconds} ms."
</syntaxhighlight>
</lang>
 
{{out}}
Line 3,813 ⟶ 4,001:
=={{header|Oforth}}==
 
<langsyntaxhighlight lang="oforth">import: mapping
import: quicksort
import: math
Line 3,849 ⟶ 4,037:
]
"non-terminating"
;</langsyntaxhighlight>
 
{{out}}
Line 3,889 ⟶ 4,077:
=={{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 ⟶ 4,094:
);
printf("%16d: %10s, %s\n", x, m, Vec(L));
}</langsyntaxhighlight>
 
Output:
Line 3,938 ⟶ 4,126:
=={{header|Perl}}==
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">use ntheory qw/divisor_sum/;
 
sub aliquot {
Line 3,973 ⟶ 4,161:
my($class, @seq) = aliquot($n);
printf "%14d %10s [@seq]\n", $n, $class;
}</langsyntaxhighlight>
{{out}}
<pre> 1 terminates [1 0]
Line 4,003 ⟶ 4,191:
=={{header|Phix}}==
Translated from the Python example
<!--<langsyntaxhighlight Phixlang="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 ⟶ 4,220:
<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 ⟶ 4,251:
=={{header|Picat}}==
{{trans|C++}}
<langsyntaxhighlight Picatlang="picat">divisor_sum(N) = R =>
Total = 1,
Power = 2,
Line 4,119 ⟶ 4,307:
nl
end.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 4,150 ⟶ 4,338:
{{works with|PowerShell|4.0}}<br/>
<b>Simple</b>
<langsyntaxhighlight lang="powershell">function Get-NextAliquot ( [int]$X )
{
If ( $X -gt 1 )
Line 4,183 ⟶ 4,371:
(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 ⟶ 4,435:
(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 ⟶ 4,462:
 
===Version 3.0===
<syntaxhighlight lang="powershell">
<lang PowerShell>
function Get-Aliquot
{
Line 4,365 ⟶ 4,553:
}
}
</syntaxhighlight>
</lang>
<syntaxhighlight lang="powershell">
<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 ⟶ 4,560:
$numbers = $oneToTen, $selected
$numbers
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 4,405 ⟶ 4,593:
{{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 ⟶ 4,661:
write_aliquot_sequence(N, Sequence, Class),
fail.
main.</langsyntaxhighlight>
 
{{out}}
Line 4,505 ⟶ 4,693:
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 ⟶ 4,733:
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 ⟶ 4,765:
{{works with|QBasic|1.1}}
{{trans|Liberty BASIC}}
<langsyntaxhighlight QBasiclang="qbasic">DECLARE FUNCTION PDtotal! (n!)
DECLARE SUB PrintAliquotClassifier (K!)
CLS
Line 4,632 ⟶ 4,820:
IF clase = 0 THEN COLOR 12: PRINT " non-terminating"
COLOR 7
END SUB</langsyntaxhighlight>
{{out}}
<pre>Number 1 : 0 Terminating
Line 4,663 ⟶ 4,851:
'''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 ⟶ 4,903:
 
(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 ⟶ 4,935:
(formerly Perl 6)
{{works with|rakudo|2018.10}}
<syntaxhighlight lang="raku" perl6line>sub propdivsum (\x) {
my @l = x > 1;
(2 .. x.sqrt.floor).map: -> \d {
Line 4,780 ⟶ 4,968:
11, 12, 28, 496, 220, 1184, 12496, 1264460,
790, 909, 562, 1064, 1488,
15355717786080;</langsyntaxhighlight>
{{out}}
<pre>1 terminating [1]
Line 4,818 ⟶ 5,006:
 
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 For types of aliquot sequences. */
parseParse argArg low high $L LL /*obtain optional arguments from the CL*/
high= word(high low 10,1); low= word(low 1,1) /*obtain the LOW and HIGH (range). */
low=word(low 1,1) /*obtain the LOW and HIGH (range). */
if $L='' then $L=11 12 28 496 220 1184 12496 1264460 790 909 562 1064 1488 15355717786080
If LL='' Then
numeric digits 100 /*be able to compute the number: BIG */
LL=11 12 28 496 220 1184 12496 1264460 790 909 562 1064 1488 15355717786080
big= 2**47; NTlimit= 16 + 1 /*limits for a non─terminating sequence*/
numericNumeric Digits 20 digits max(9, length(big) ) /*be able toTo handlecompute bigthe numbersnumber: for //BIG */
big=2**47
digs= digits() /*used for align numbers for the output*/
#.NTlimit=16+1 .; #.0= 0; #.1= 0 /*#. are the proper divisorlimit sums.for a non-terminating sequence */
Numeric Digits max(9,length(big)) /*be able To handle big numbers For // */
say center('numbers from ' low " ───► " high ' (inclusive)', 153, "═")
digs=digits() do n=low to high; call classify n /*callused For aalign subroutinenumbers toFor classifythe number.output*/
dsum.=.
end /*n*/ /* [↑] process a range of integers. */
dsum.0=0
say
dsum.1=0 /* dsum. are the proper divisor sums. */
say center('first numbers for each classification', 153, "═")
Say 'Numbers from ' low ' ---> ' high ' (inclusive):'
class.= 0 /* [↓] ensure one number of each class*/
Do n=low To high do q=1 until class.sociable\==0 /*the onlyprocess specified range one that has to be counted. */
Call classify n call classify -q /*minus (-)call signsubroutine indicatesTo don'tclassify tellnumber. */
End
_= what; upper _ /*obtain the class and uppercase it. */
Say
class._= class._ + 1 /*bump counter for this class sequence.*/
Say 'First numbers for each classification:'
if class._==1 then say right(q, digs)':' center(what, digs) $
class.=0 end /*q*/ /* [?] onlyensure one displaynumber theof 1steach occurrenceclass*/
say Do q=1 Until class.sociable\==0 /*the only [↑]one that processhas untilTo allbe classescounted. found*/
Call classify -q /*minus (-) sign indicates don't tell. */
say center('classifications for specific numbers', 153, "═")
_=translate(what) do i=1 for words($L) /*$L:obtain the isclass aand listuppercase ofit. "special numbers".*/
class._=class._+1 call classify word($L, i) /*callbump acounter subroutineFor tothis classifyclass numbersequence.*/
If class._==1 Then end /*i*/ /*first number of this class /* [↑] process a list of integers. */
Call out q,what,dd
exit /*stick a fork in it, we're all done. */
End
/*──────────────────────────────────────────────────────────────────────────────────────*/
classify:Say parse arg a 1 aa; a= abs(a) /*obtain number[?] process that'sUntil toall beclasses classifiedfound*/
Say 'Classifications for specific numbers:'
if #.a\==. then s= #.a /*Was this number been summed before?*/
Do i=1 To words(LL) else s= sigma(a) /*No, thenprocess a classifylist numberof the"special hardnumbers" way*/
Call classify #.a= s word(LL,i) /*define sum ofcall thesubroutine To properclassify divisorsnumber. */
End
$= s /*define the start of integer sequence.*/
Exit what= 'terminating' /*assumestick thisa kindfork ofin classificationit,we're all done. */
out:
c.= 0 /*clear all cyclic sequences (to zero).*/
Parse arg number,class,dd
c.s= 1 /*set the first cyclic sequence. */
dd.=''
if $==a then what= 'perfect' /*check for a "perfect" number. */
Do di=1 By 1 While length(dd)>50
else do t=1 while s>0 /*loop until sum isn't 0 or > big.*/
do dj=50 To 10 By -1
m= s /*obtain the last number in sequence. */
If substr(dd,dj,1)=' ' Then Leave
if #.m==. then s= sigma(m) /*Not defined? Then sum proper divisors*/
End
else s= #.m /*use the previously found integer. */
dd.di=left(dd,dj)
if m==s then if m>=0 then do; what= 'aspiring'; leave; end
dd=substr(dd,dj+1)
parse var $ . word2 . /*obtain the 2nd number in sequence. */
End
if word2==a then do; what= 'amicable'; leave; end
dd.di=dd
$= $ s /*append a sum to the integer sequence.*/
Say right(number,digs)':' center(class,digs) dd.1||conti(1)
if s==a then if t>3 then do; what= 'sociable'; leave; end
Do di=2 By 1 While dd.di>''
if c.s then if m>0 then do; what= 'cyclic' ; leave; end
Say copies(' ',33)dd.di||conti(di)
c.s= 1 /*assign another possible cyclic number*/
End
/* [↓] Rosetta Code task's limit: >16 */
Return
if t>NTlimit then do; what= 'non─terminating'; leave; end
conti:
if s>big then do; what= 'NON─TERMINATING'; leave; end
Parse arg this
end /*t*/ /* [↑] only permit within reason. */
next=this+1
if aa>0 then say right(a, digs)':' center(what, digs) $
If dd.next>'' Then Return '...'
return /* [↑] only display if AA is positive*/
Else Return ''
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*---------------------------------------------------------------------------------*/
sigma: procedure expose #. !.; parse arg x; if 11<2 then return 0; odd= x // 2
classify:
s= 1 /* [↓] use EVEN or ODD integers. ___*/
Parse Arg a 1 aa
do j=2+odd by 1+odd while j*j<x /*divide by all the integers up to √ X */
a=abs(a) if x//j==0 then s= s + j + x % j /*add the two divisors to the sum. /*obtain number that's to be classified*/
If dsum.a\==. Then
end /*j*/ /* [↓] adjust for square. ___*/
if j*js==xdsum.a then s= s + j /*Was X a square? /*Was Ifthis so,number addbeen summed X before?*/
Else
#.x= s /*memoize division sum for argument X.*/
return s =dsum(a) /*returnNo,Then classify number the hard " " " " "way */</lang>
dsum.a=s /*define sum of the proper divisors. */
dd=s /*define the start of integer sequence.*/
what='terminating' /*assume this kind of classification. */
c.=0 /*clear all cyclic sequences (to zero).*/
c.s=1 /*set the first cyclic sequence. */
If dd==a Then
what='perfect' /*check For a "perfect" number. */
Else Do t=1 By 1 While s>0 /*loop Until sum isn't 0 or > big.*/
m=s /*obtain the last number in sequence. */
If dsum.m==. Then /*Not defined? */
s=dsum(m) /* compute sum pro of per divisors */
Else
s=dsum.m /*use the previously found integer. */
If m==s Then
If m>=0 Then Do
what='aspiring'
Leave
End
If word(dd,2)=a Then Do
what='amicable'
Leave
End
dd=dd s /*append a sum To the integer sequence.*/
If s==a Then
If t>3 Then Do
what='sociable'
Leave
End
If c.s Then
If m>0 Then Do
what='cyclic'
Leave
End
c.s=1 /*assign another possible cyclic number*/
/* [?] Rosetta Code task's limit: >16 */
If t>NTlimit Then Do
what='non-terminating'
Leave
End
If s>big Then Do
what='NON-TERMINATING'
Leave
End
End
If aa>0 Then /* display only if AA is positive */
Call out a,what,dd
Return
/*---------------------------------------------------------------------------------*/
dsum: Procedure Expose dsum. /* compute the sum of proper divisors */
Parse Arg x
If x<2 Then
Return 0
odd=x//2
s=1 /* use EVEN or ODD integers. */
Do j=2+odd by 1+odd While j*j<x /* divide by all the integers ) */
/* up to but excluding sqrt(x) */
If x//j==0 Then /* j is a divisor, so is x%j */
s=s+j+x%j /*add the two divisors To the sum. */
End
If j*j==x Then /* if x is a square */
s=s+j /* add sqrt(X) */
dsum.x=s /* memoize proper divisor sum of X */
Return s /* return the proper divisor sum */
</syntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
<pre>Numbers from 1 ---> 10 (inclusive):
(Shown at three-quarter size.)
 
<pre style="font-size:75%">
═════════════════════════════════════════════════════════numbers from 1 ───► 10 (inclusive)══════════════════════════════════════════════════════════
1: terminating 0
2: terminating 1 0
Line 4,897 ⟶ 5,146:
10: terminating 8 7 1 0
 
First numbers for each classification:
══════════════════════════════════════════════════════════first numbers for each classification══════════════════════════════════════════════════════════
1: terminating 0
6: perfect 6
25: aspiring 6
138: non─terminatingnon-terminating 150 222 234 312 528 960 2088 3762 5598 6570 10746 13254 13830 19434 20886 21606 25098 26742 26754...
13254 13830 19434 20886 21606 25098 26742 26754
220: amicable 284 220
562: cyclic 284 220 284
12496: sociable 14288 15472 14536 14264 12496
 
Classifications for specific numbers:
══════════════════════════════════════════════════════════classifications for specific numbers═══════════════════════════════════════════════════════════
11: terminating 1 0
12: terminating 16 15 9 4 3 1 0
Line 4,919 ⟶ 5,169:
562: cyclic 284 220 284
1064: cyclic 1336 1184 1210 1184
1488: non─terminatingnon-terminating 2480 3472 4464 8432 9424 10416 21328 22320 55056 95728 96720 236592 459792 881392 882384 1474608 2461648 3172912 3173904...
95728 96720 236592 459792 881392 882384 1474608 ...
15355717786080: NON─TERMINATING 44534663601120 144940087464480
2461648 3172912 3173904
15355717786080: NON-TERMINATING 44534663601120 144940087464480
 
</pre>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Aliquot sequence classnifications
 
Line 5,003 ⟶ 5,256:
next
return pdtotal
</syntaxhighlight>
</lang>
Output:
<pre>
Line 5,068 ⟶ 5,321:
Enter an integer:
Program complete.
</pre>
 
=={{header|RPL}}==
{{works with|HP|49}}
≪ DIVIS DUP SIZE
'''IF''' DUP 2 ≤ '''THEN''' 1 - NIP '''ELSE''' 1 SWAP 1 - SUB ∑LIST '''END'''
R→I
≫ ≫ ‘<span style="color:blue">∑PFAC</span>’ STO
≪ 16 2 47 ^ → smax vmax
≪ { } OVER +
'''DO'''
SWAP <span style="color:blue">∑PFAC</span> SWAP OVER +
'''UNTIL''' OVER NOT LASTARG vmax ≥ OR OVER SIZE smax ≥ OR
'''END''' NIP
≫ ≫ ‘<span style="color:blue">ALIQT</span>’ STO
≪ <span style="color:blue">ALIQT</span> DUP HEAD → seq k
≪ '''CASE'''
seq 0 POS '''THEN''' "terminating" '''END'''
seq 2 GET k == '''THEN''' "perfect" '''END'''
seq 3 GET k == '''THEN''' "amicable" '''END'''
seq 4 OVER SIZE SUB k POS '''THEN''' "sociable" '''END'''
seq ΔLIST 0 POS '''THEN''' "aspiring" '''END'''
seq SORT ΔLIST 0 POS '''THEN''' "cyclic" '''END'''
"non-terminating"
'''END'''
≫ ≫ ‘<span style="color:blue">ALIQLASS</span>’ STO
 
≪ n <span style="color:blue">ALIQLASS</span> ≫ 'n' 1 10 1 SEQ
{11 12 28 496 220 1184 12496 1264460 790 909 562 1064 1488 15355717786080} 1 ≪ <span style="color:blue">ALIQLASS</span> ≫ DOLIST
{{out}}
<pre>
2: { "terminating" "terminating" "terminating" "terminating" "terminating" "terminating" "perfect" "terminating" "terminating" "terminating" }
1: { "terminating" "terminating" "perfect" "perfect" "amicable" "amicable" "sociable" "sociable" "aspiring" "aspiring" "cyclic" "cyclic" "non-terminating" "non-terminating" }
</pre>
 
Line 5,074 ⟶ 5,363:
{{trans|Python}}
 
<langsyntaxhighlight lang="ruby">def aliquot(n, maxlen=16, maxterm=2**47)
return "terminating", [0] if n == 0
s = []
Line 5,102 ⟶ 5,391:
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 ⟶ 5,423:
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">#[derive(Debug)]
enum AliquotType { Terminating, Perfect, Amicable, Sociable, Aspiring, Cyclic, NonTerminating }
 
Line 5,178 ⟶ 5,467:
println!("{} {:?}", num, classify_aliquot(*num));
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 5,208 ⟶ 5,497:
=={{header|Scala}}==
Put [[proper_divisors#Scala]] the full /Proper divisors for big (long) numbers/ section to the beginning:
<langsyntaxhighlight Scalalang="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 ⟶ 5,516:
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 ⟶ 5,546:
=={{header|Swift}}==
 
<langsyntaxhighlight lang="swift">extension BinaryInteger {
@inlinable
public func factors(sorted: Bool = true) -> [Self] {
Line 5,323 ⟶ 5,612:
print()
 
print("\(15355717786080): \(classifySequence(k: 15355717786080))")</langsyntaxhighlight>
 
{{out}}
Line 5,358 ⟶ 5,647:
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 Tcllang="tcl">proc ProperDivisors {n} {
if {$n == 1} {return 0}
set divs 1
Line 5,430 ⟶ 5,719:
puts [time {
puts [format "%8d -> %-16s : %s" $i {*}[al_classify $i]]
}]</langsyntaxhighlight>
 
{{out}}
Line 5,464 ⟶ 5,753:
 
=={{header|VBA}}==
<langsyntaxhighlight lang="vb">Option Explicit
 
Private Type Aliquot
Line 5,530 ⟶ 5,819:
SumPDiv = t
End Function
</syntaxhighlight>
</lang>
 
{{out}}
Line 5,558 ⟶ 5,847:
</pre>
 
=={{header|V (Vlang)}}==
{{trans|Go}}
<syntaxhighlight lang="v (vlang)">import math
const threshold = u64(1) << 47
Line 5,664 ⟶ 5,953:
seq, aliquot := classify_sequence(k)
println("$k: ${aliquot:-15} $seq")
}</langsyntaxhighlight>
 
{{out}}
Line 5,703 ⟶ 5,992:
{{libheader|Wren-math}}
{{libheader|Wren-seq}}
<langsyntaxhighlight ecmascriptlang="wren">import "./fmt" for Conv, Fmt
import "./math" for Int, Nums
import "./seq" for Lst
class Classification {
Line 5,741 ⟶ 6,030:
for (k in 1..10) {
var c = classifySequence.call(k)
SystemFmt.print("%(Fmt.d(2, k))$2d: %(Fmt.s($-1515s $n", k, c.aliquot)), %(c.seq)")
}
Line 5,748 ⟶ 6,037:
for (k in a) {
var c = classifySequence.call(k)
SystemFmt.print("%(Fmt.d(7, k))$7d: %(Fmt.s($-1515s $n", k, c.aliquot)), %(c.seq)")
}
Line 5,755 ⟶ 6,044:
var c = classifySequence.call(k)
var seq = c.seq.map { |i| Conv.dec(i) }.toList // ensure 15 digit integer is printed in full
SystemFmt.print("%(k)$d: %(Fmt.s($-1515s $n", k, c.aliquot)), %(seq)")</langsyntaxhighlight>
 
{{out}}
Line 5,791 ⟶ 6,080:
=={{header|Yabasic}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight Yabasiclang="yabasic">// Rosetta Code problem: http://rosettacode.org/wiki/Aliquot_sequence_classifications
// by Galileo, 05/2022
 
Line 5,851 ⟶ 6,140:
if not n break
alliquot(n)
loop</langsyntaxhighlight>
{{out}}
<pre>Integer: 1, Type: Terminating, Series: 1
Line 5,879 ⟶ 6,168:
 
=={{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 ⟶ 6,181:
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 ⟶ 6,203:
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 ⟶ 6,239:
{{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 ⟶ 6,279:
2320 NEXT t
2330 LET s$="non-terminating (after 16 terms)"+s$
2340 RETURN</langsyntaxhighlight>
{{out}}
<pre>Number classification sequence
2,289

edits