38 lines
1.1 KiB
Text
38 lines
1.1 KiB
Text
require "table2"
|
|
local int = require "int"
|
|
local fmt = require "fmt"
|
|
|
|
local limit = 100
|
|
local starts = {2, 5, 7, 9, 10}
|
|
local ekg = {}
|
|
for i = 1, 5 do ekg[i] = table.rep(limit, 0) end
|
|
local s = 1
|
|
for starts as start do
|
|
ekg[s][1] = 1
|
|
ekg[s][2] = start
|
|
for n = 3, limit do
|
|
local i = 2
|
|
while true do
|
|
-- A potential sequence member cannot already have been used
|
|
-- and must have a factor in common with previous member.
|
|
if !ekg[s]:slice(1, n):contains(i) and int.gcd(ekg[s][n - 1], i) > 1 then
|
|
ekg[s][n] = i
|
|
break
|
|
end
|
|
i += 1
|
|
end
|
|
end
|
|
fmt.write("EKG(%2d): ", start)
|
|
fmt.tprint("%2d", ekg[s]:slice(1, 30), 30)
|
|
s += 1
|
|
end
|
|
|
|
-- Now compare EKG5 and EKG7 for convergence.
|
|
for i = 3, limit do
|
|
if ekg[2][i] == ekg[3][i] and
|
|
table.same(ekg[2]:slice(1, i - 1):sort(), ekg[3]:slice(1, i - 1):sort()) then
|
|
print($"\nEKG(5) and EKG(7) converge at term {i}.")
|
|
os.exit()
|
|
end
|
|
end
|
|
print($"\nEKG5(5) and EKG(7) do not converge within {limit} terms.")
|