(phixonline)-->
with javascript_semantics
constant LIMIT = 100
constant starts = {2, 5, 7, 9, 10}
sequence ekg = {}
string fmt = "EKG(%2d): ["&join(repeat("%d",min(LIMIT,30))," ")&"]\n"
for s=1 to length(starts) do
ekg = append(ekg,{1,starts[s]}&repeat(0,LIMIT-2))
for n=3 to LIMIT do
-- a potential sequence member cannot already have been used
-- and must have a factor in common with previous member
integer i = 2
while find(i,ekg[s])
or gcd(ekg[s][n-1],i)<=1 do
i += 1
end while
ekg[s][n] = i
end for
printf(1,fmt,starts[s]&ekg[s][1..min(LIMIT,30)])
end for
-- now compare EKG5 and EKG7 for convergence
constant EKG5 = find(5,starts),
EKG7 = find(7,starts)
string msg = sprintf("do not converge within %d terms", LIMIT)
for i=3 to LIMIT do
if ekg[EKG5][i]=ekg[EKG7][i]
and sort(ekg[EKG5][1..i-1])=sort(ekg[EKG7][1..i-1]) then
msg = sprintf("converge at term %d", i)
exit
end if
end for
printf(1,"\nEKG5(5) and EKG(7) %s\n", msg)