Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
64
Task/Arithmetic-numbers/Oberon-07/arithmetic-numbers.oberon
Normal file
64
Task/Arithmetic-numbers/Oberon-07/arithmetic-numbers.oberon
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
MODULE ArithmeticNumbers;
|
||||
IMPORT Out;
|
||||
|
||||
CONST
|
||||
Max = 130000;
|
||||
|
||||
VAR divSum: ARRAY Max + 1 OF INTEGER;
|
||||
divCount: ARRAY Max + 1 OF CHAR;
|
||||
current, count, composites: INTEGER;
|
||||
|
||||
PROCEDURE CalculateDivisorSums;
|
||||
VAR div, num: INTEGER;
|
||||
BEGIN
|
||||
FOR num := 1 TO Max DO
|
||||
divSum[num] := 0;
|
||||
divCount[num] := CHR(0)
|
||||
END;
|
||||
|
||||
FOR div := 1 TO Max DO
|
||||
num := div;
|
||||
WHILE num <= Max DO
|
||||
INC(divSum[num],div);
|
||||
divCount[num] := CHR(ORD(divCount[num]) + 1);
|
||||
INC(num,div)
|
||||
END
|
||||
END
|
||||
END CalculateDivisorSums;
|
||||
|
||||
PROCEDURE Next(n: INTEGER): INTEGER;
|
||||
BEGIN
|
||||
REPEAT INC(n) UNTIL (divSum[n] MOD ORD(divCount[n])) = 0;
|
||||
RETURN n
|
||||
END Next;
|
||||
|
||||
PROCEDURE Composite(n: INTEGER): BOOLEAN;
|
||||
BEGIN
|
||||
RETURN (n>1) & (divSum[n] # n+1)
|
||||
END Composite;
|
||||
|
||||
BEGIN
|
||||
CalculateDivisorSums;
|
||||
Out.String("First 100 arithmetic numbers:");
|
||||
Out.Ln;
|
||||
|
||||
current := 0;
|
||||
FOR count := 1 TO 100000 DO
|
||||
current := Next(current);
|
||||
IF Composite(current) THEN INC(composites) END;
|
||||
IF count <= 100 THEN
|
||||
Out.Int(current, 5);
|
||||
IF count MOD 10 = 0 THEN Out.Ln END
|
||||
END;
|
||||
|
||||
IF (count = 1000) OR (count = 10000) OR (count = 100000) THEN
|
||||
Out.Int(count, 6);
|
||||
Out.String("th: ");
|
||||
Out.Int(current, 6);
|
||||
Out.String(", ");
|
||||
Out.Int(composites, 6);
|
||||
Out.String(" composites");
|
||||
Out.Ln
|
||||
END;
|
||||
END
|
||||
END ArithmeticNumbers.
|
||||
49
Task/Arithmetic-numbers/REXX/arithmetic-numbers.rexx
Normal file
49
Task/Arithmetic-numbers/REXX/arithmetic-numbers.rexx
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
include Settings
|
||||
|
||||
say version; say 'Arithmetic numbers'; say
|
||||
numeric digits 9
|
||||
a = 0; c = 0
|
||||
do i = 1
|
||||
/* Is the number arithmetic? */
|
||||
if Arithmetic(i) then do
|
||||
a = a+1
|
||||
/* Is the number composite? */
|
||||
if divi.0 > 2 then
|
||||
c = c+1
|
||||
/* Output control */
|
||||
if a <= 100 then do
|
||||
if a = 1 then
|
||||
say 'First 100 arithmetic numbers are'
|
||||
call Charout ,Right(i,4)
|
||||
if a//10 = 0 then
|
||||
say
|
||||
if a = 100 then
|
||||
say
|
||||
end
|
||||
if a = 100 | a = 1000 | a = 10000 | a = 100000 | a = 1000000 then do
|
||||
say 'The' a'th arithmetic number is' i
|
||||
say 'Of the first' a 'numbers' c 'are composite'
|
||||
say
|
||||
end
|
||||
/* Max 1m, higher takes too long */
|
||||
if a = 1000000 then
|
||||
leave
|
||||
end
|
||||
end
|
||||
say Format(Time('e'),,3) 'seconds'
|
||||
exit
|
||||
|
||||
Arithmetic:
|
||||
/* Is a number arithmetic? function */
|
||||
procedure expose divi.
|
||||
arg x
|
||||
/* Cf definition */
|
||||
s = Sigma(x)
|
||||
if Iswhole(s/divi.0) then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
|
||||
include Numbers
|
||||
include Functions
|
||||
include Abend
|
||||
Loading…
Add table
Add a link
Reference in a new issue