41 lines
780 B
Text
41 lines
780 B
Text
sequence sb = {1,1}
|
|
integer c = 2
|
|
|
|
function stern_brocot(integer n)
|
|
while length(sb)<n do
|
|
sb &= sb[c]+sb[c-1] & sb[c]
|
|
c += 1
|
|
end while
|
|
return sb[1..n]
|
|
end function
|
|
|
|
sequence s = stern_brocot(15)
|
|
puts(1,"first 15:")
|
|
?s
|
|
integer n = 16, k
|
|
sequence idx = tagset(10)
|
|
for i=1 to length(idx) do
|
|
while 1 do
|
|
k = find(idx[i],s)
|
|
if k!=0 then exit end if
|
|
n *= 2
|
|
s = stern_brocot(n)
|
|
end while
|
|
idx[i] = k
|
|
end for
|
|
puts(1,"indexes of 1..10:")
|
|
?idx
|
|
puts(1,"index of 100:")
|
|
while 1 do
|
|
k = find(100,s)
|
|
if k!=0 then exit end if
|
|
n *= 2
|
|
s = stern_brocot(n)
|
|
end while
|
|
?k
|
|
s = stern_brocot(1000)
|
|
integer maxgcd = 1
|
|
for i=1 to 999 do
|
|
maxgcd = max(gcd(s[i],s[i+1]),maxgcd)
|
|
end for
|
|
printf(1,"max gcd:%d\n",{maxgcd})
|