(phixonline)-->
with javascript_semantics
function farey(integer n)
integer a=0, b=1, c=1, d=n, items=1
if n<=11 then
printf(1,"%d: %d/%d",{n,a,b})
end if
while c<=n do
integer k = floor((n+b)/d)
{a,b,c,d} = {c,d,k*c-a,k*d-b}
items += 1
if n<=11 then
printf(1," %d/%d",{a,b})
end if
end while
return items
end function
printf(1,"Farey sequence for order 1 through 11:\n")
for i=1 to 11 do
{} = farey(i)
printf(1,"\n")
end for
sequence nf = apply(tagset(1000,100,100),farey)
printf(1,"Farey sequence fractions, 100 to 1000 by hundreds:\n%v\n",{nf})