Data update

This commit is contained in:
Ingy döt Net 2025-08-11 18:05:26 -07:00
parent 4d5544505c
commit 4924dd0264
3073 changed files with 55820 additions and 4408 deletions

View file

@ -0,0 +1,26 @@
scope # 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 otherwise
local procedure VanEck( n :: number ) :: sequence # returns the first n elements of the Van Eck sequence
local constant result := seq(); for i to n do result[ i ] := 0 od;
local constant pos := seq(); for i to n + 1 do pos[ i ] := 0 od;
for i from 2 to n do
local constant j := i - 1;
local constant prev := result[ j ] + 1; # prev is indexed from 1, not 0
if pos[ prev ] <> 0 then
# not a new element
result[ i ] := j - pos[ prev ]
fi;
pos[ prev ] := j
od;
return result
end;
local constant veSeq := VanEck( 1000 ); # construct the first 1000 terms of the sequence
# show the first and last 10 elements
for i to 10 do printf( " %d", veSeq[ i ] ) od;
printf( "\n" );
for i from size veSeq - 9 to size veSeq do printf( " %d", veSeq[ i ] ) od;
printf( "\n" )
end

View file

@ -0,0 +1,26 @@
do --[[ 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 otherwise
]]
local fmt = require( "fmt" ) -- RC formatting module
local function VanEck( n : number ) : table -- returns the first n elements of the Van Eck sequence
local result <const> = {} for i = 1, n do result[ i ] = 0 end
local pos <const> = {} for i = 1, n + 1 do pos[ i ] = 0 end
for i = 2, n do
local j <const> = i - 1
local prev <const> = result[ j ] + 1; -- prev is indexed from 1, not 0
if pos[ prev ] != 0 then
-- not a new element
result[ i ] = j - pos[ prev ]
end
pos[ prev ] = j
end
return result
end
local veSeq <const> = VanEck( 1000 ) -- construct the first 1000 terms of the sequence
-- show the first and last 10 elements
fmt.lprint( veSeq:slice( 1, 10 ) )
fmt.lprint( veSeq:slice( # veSeq - 9, # veSeq ) )
end