44 lines
831 B
Plaintext
44 lines
831 B
Plaintext
local fn FareySequence( n as long, descending as BOOL )
|
|
long a = 0, b = 1, c = 1, d = n, k = 0
|
|
long aa, bb, cc, dd
|
|
long count = 0
|
|
|
|
if descending = YES
|
|
a = 1
|
|
c = n -1
|
|
end if
|
|
|
|
count++
|
|
if n < 12 then print a; "/"; b; " ";
|
|
|
|
while ( (c <= n) and not descending ) or ( (a > 0) and descending)
|
|
aa = a
|
|
bb = b
|
|
cc = c
|
|
dd = d
|
|
k = int( (n + b) / d )
|
|
a = cc
|
|
b = dd
|
|
c = k * cc - aa
|
|
d = k * dd - bb
|
|
count++
|
|
if n < 12 then print a;"/"; b; " ";
|
|
wend
|
|
|
|
if n < 12 then print else print count
|
|
end fn
|
|
|
|
long i
|
|
|
|
for i = 1 to 11
|
|
if i < 10 then printf @" F%ld = \b", i else printf @"F%ld = \b", i
|
|
fn FareySequence( i, NO )
|
|
next
|
|
print
|
|
for i = 100 to 1000 step 100
|
|
if i < 1000 then printf @" F%ld = \b", i else printf @"F%ld = \b", i
|
|
fn FareySequence( i, NO )
|
|
next
|
|
|
|
HandleEvents
|