Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
26
Task/Van-Eck-sequence/Pluto/van-eck-sequence.pluto
Normal file
26
Task/Van-Eck-sequence/Pluto/van-eck-sequence.pluto
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue