Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,35 @@
with Ada.Text_IO;
procedure Van_Eck_Sequence is
Sequence : array (Natural range 1 .. 1_000) of Natural;
procedure Calculate_Sequence is
begin
Sequence (Sequence'First) := 0;
for Index in Sequence'First .. Sequence'Last - 1 loop
Sequence (Index + 1) := 0;
for I in reverse Sequence'First .. Index - 1 loop
if Sequence (I) = Sequence (Index) then
Sequence (Index + 1) := Index - I;
exit;
end if;
end loop;
end loop;
end Calculate_Sequence;
procedure Show (First, Last : in Positive) is
use Ada.Text_IO;
begin
Put ("Element" & First'Image & " .." & Last'Image & " of Van Eck sequence: ");
for I in First .. Last loop
Put (Sequence (I)'Image);
end loop;
New_Line;
end Show;
begin
Calculate_Sequence;
Show (First => 1, Last => 10);
Show (First => 991, Last => 1_000);
end Van_Eck_Sequence;

View file

@ -0,0 +1,46 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. VAN-ECK.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CALCULATION.
02 ECK PIC 999 OCCURS 1000 TIMES.
02 I PIC 9999.
02 J PIC 9999.
01 OUTPUT-FORMAT.
02 ITEM PIC ZZ9.
02 IDX PIC ZZZ9.
PROCEDURE DIVISION.
B. PERFORM GENERATE-ECK.
PERFORM SHOW VARYING I FROM 1 BY 1 UNTIL I = 11.
PERFORM SHOW VARYING I FROM 991 BY 1 UNTIL I = 1001.
STOP RUN.
SHOW.
MOVE I TO IDX.
MOVE ECK(I) TO ITEM.
DISPLAY 'ECK(' IDX ') = ' ITEM.
GENERATE-ECK SECTION.
B. SET ECK(1) TO 0.
SET I TO 1.
PERFORM GENERATE-TERM
VARYING I FROM 2 BY 1 UNTIL I = 1001.
GENERATE-TERM SECTION.
B. SUBTRACT 2 FROM I GIVING J.
LOOP.
IF J IS LESS THAN 1 GO TO TERM-IS-NEW.
IF ECK(J) = ECK(I - 1) GO TO TERM-IS-OLD.
SUBTRACT 1 FROM J.
GO TO LOOP.
TERM-IS-NEW.
SET ECK(I) TO 0.
GO TO DONE.
TERM-IS-OLD.
COMPUTE ECK(I) = (I - J) - 1.
DONE. EXIT.

View file

@ -0,0 +1,27 @@
fun vanEck ← void by int firstIndex, int lastIndex
logic isFirst ← true
Map map ← int%int[]
int last ← 0
write("[")
if firstIndex æ 1
write("0")
isFirst ← false
end
for int n ← 2 ; n ≤ lastIndex ; ++n
int v ← when(map.has(last), n - map[last], 0)
map[last] ← n
last ← v
if n ≥ firstIndex
write(when(isFirst, Text.EMPTY, ",") + v)
isFirst ← false
end
end
writeLine("]")
end
Pair[int%int(1 ⇒ 10), int%int(991 ⇒ 1000)].list(
void by var pair
writeLine("Terms " + pair.key + " to " +
pair.value + " of the sequence are:")
vanEck(pair.key, pair.value)
writeLine()
end)

View file

@ -0,0 +1,36 @@
MODULE VanEck; (* find elements of the Van Eck Sequence - first term is 0, following *)
(* terms are 0 if the previous was the first appearance of the element *)
(* or how far back in the sequence the last element appeared *)
IMPORT Out;
VAR vSeq, vPos : ARRAY 1001 OF INTEGER;
i : INTEGER;
(* Stores the first LEN( seq ) - 1 elements of the Van Eck sequence into seq *)
(* ( element 0 is not used ), pos must be the same length as seq and is used as a *)
(* temporary work array *)
PROCEDURE getVanEck( VAR seq, pos : ARRAY OF INTEGER );
VAR i, j, n, prev : INTEGER;
BEGIN
n := LEN( seq ) - 1;
FOR i := 0 TO n DO seq[ i ] := 0; pos[ i ] := 0 END;
FOR i := 2 TO n DO
j := i - 1;
prev := seq[ j ];
IF pos[ prev ] # 0 THEN (* not a new element *)
seq[ i ] := j - pos[ prev ]
END;
pos[ prev ] := j
END
END getVanEck;
BEGIN
(* construct the first 1000 terms of the sequence *)
getVanEck( vSeq, vPos );
(* show the first and last 10 elements *)
FOR i := 1 TO 10 DO Out.String( " " );Out.Int( vSeq[ i ], 0 ) END;Out.Ln;
FOR i := LEN( vSeq ) - 10 TO LEN( vSeq ) - 1 DO Out.String( " " );Out.Int( vSeq[ i ], 0 ) END;Out.Ln
END VanEck.