RosettaCodeData/Task/Stern-Brocot-sequence/Yabasic/stern-brocot-sequence.basic

57 lines
1023 B
Plaintext

limite = 2000
dim stern(limite+2)
sub SternBrocot()
stern(1) = 1
stern(2) = 1
i = 2 : n = 2 : ub = arraysize(stern(),1)
while i < ub
i = i + 1
stern(i) = stern(n) + stern(n -1)
i = i + 1
stern(i) = stern(n)
n = n + 1
wend
end sub
sub gcd(p, q)
if q = 0 return p
return gcd(q, mod(p, q))
end sub
SternBrocot()
print "The first 15 are: ";
for i = 1 to 15
print stern(i), " ";
next i
print "\n\n Index First nr."
d = 1
for i = 1 to limite
if stern(i) = d then
print i using "######", stern(i) using "######"
d = d + 1
if d = 11 d = 100
if d = 101 break
i = 0
end if
next i
print : print
d = 0
for i = 1 to 1000
if gcd(stern(i), stern(i+1)) <> 1 then
d = gcd(stern(i), stern(i+1))
break
end if
next i
if d = 0 then
print "GCD of two consecutive members of the series up to the 1000th member is 1"
else
print "The GCD for index ", i, " and ", i+1, " = ", d
end if