Farey sequence: Difference between revisions

no edit summary
m (→‎{{header|jq}}: include)
No edit summary
Line 1,492:
1000: 304193
</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
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
</syntaxhighlight>
{{output}}
<pre>
F1 = 0/1 1/1
F2 = 0/1 1/2 1/1
F3 = 0/1 1/3 1/2 2/3 1/1
F4 = 0/1 1/4 1/3 1/2 2/3 3/4 1/1
F5 = 0/1 1/5 1/4 1/3 2/5 1/2 3/5 2/3 3/4 4/5 1/1
F6 = 0/1 1/6 1/5 1/4 1/3 2/5 1/2 3/5 2/3 3/4 4/5 5/6 1/1
F7 = 0/1 1/7 1/6 1/5 1/4 2/7 1/3 2/5 3/7 1/2 4/7 3/5 2/3 5/7 3/4 4/5 5/6 6/7 1/1
F8 = 0/1 1/8 1/7 1/6 1/5 1/4 2/7 1/3 3/8 2/5 3/7 1/2 4/7 3/5 5/8 2/3 5/7 3/4 4/5 5/6 6/7 7/8 1/1
F9 = 0/1 1/9 1/8 1/7 1/6 1/5 2/9 1/4 2/7 1/3 3/8 2/5 3/7 4/9 1/2 5/9 4/7 3/5 5/8 2/3 5/7 3/4 7/9 4/5 5/6 6/7 7/8 8/9 1/1
F10 = 0/1 1/10 1/9 1/8 1/7 1/6 1/5 2/9 1/4 2/7 3/10 1/3 3/8 2/5 3/7 4/9 1/2 5/9 4/7 3/5 5/8 2/3 7/10 5/7 3/4 7/9 4/5 5/6 6/7 7/8 8/9 9/10 1/1
F11 = 0/1 1/11 1/10 1/9 1/8 1/7 1/6 2/11 1/5 2/9 1/4 3/11 2/7 3/10 1/3 4/11 3/8 2/5 3/7 4/9 5/11 1/2 6/11 5/9 4/7 3/5 5/8 7/11 2/3 7/10 5/7 8/11 3/4 7/9 4/5 9/11 5/6 6/7 7/8 8/9 9/10 10/11 1/1
 
F100 = 3045
F200 = 12233
F300 = 27399
F400 = 48679
F500 = 76117
F600 = 109501
F700 = 149019
F800 = 194751
F900 = 246327
F1000 = 304193
</pre>
 
 
=={{header|Fōrmulæ}}==
717

edits