Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
32
Task/Van-Eck-sequence/Lua/van-eck-sequence.lua
Normal file
32
Task/Van-Eck-sequence/Lua/van-eck-sequence.lua
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
-- Return a table of the first n values of the Van Eck sequence
|
||||
function vanEck (n)
|
||||
local seq, foundAt = {0}
|
||||
while #seq < n do
|
||||
foundAt = nil
|
||||
for pos = #seq - 1, 1, -1 do
|
||||
if seq[pos] == seq[#seq] then
|
||||
foundAt = pos
|
||||
break
|
||||
end
|
||||
end
|
||||
if foundAt then
|
||||
table.insert(seq, #seq - foundAt)
|
||||
else
|
||||
table.insert(seq, 0)
|
||||
end
|
||||
end
|
||||
return seq
|
||||
end
|
||||
|
||||
-- Show the set of values in table t from key numbers lo to hi
|
||||
function showValues (t, lo, hi)
|
||||
for i = lo, hi do
|
||||
io.write(t[i] .. " ")
|
||||
end
|
||||
print()
|
||||
end
|
||||
|
||||
-- Main procedure
|
||||
local sequence = vanEck(1000)
|
||||
showValues(sequence, 1, 10)
|
||||
showValues(sequence, 991, 1000)
|
||||
Loading…
Add table
Add a link
Reference in a new issue