Farey sequence: Difference between revisions

m
m (→‎{{header|Phix}}: added syntax colouring, marked p2js compatible)
Line 1,816:
<lang Maple>#Displays terms in Farey_sequence of order n
farey_sequence := proc(n)
local a,b,c,d,k;
a,b,c,d := 0,1,1,n;
printf("%d/%d", a,b);
while( c <= n) do
k := trunc(iquo(n+b)/,d);
a,b,c,d := c,d,c*k-a,d*k-b;
printf(", %d/%d", a,b);
end do;
printf("\n");
end proc;:
 
#Returns the length of a Farey sequence
farey_len := proc(n)
return 1 + add(NumberTheory:-Totient(k), k=1..n);
end proc;
 
for i to 11 do
farey_sequence(i);
end do;
printf("\n");
for j from 100 to 1000 by 100 do
printf("%d\n", farey_len(j));
end do;</lang>
 
{{Out|Output}}
<pre>
0/1, 1/1
1,336

edits