Farey sequence: Difference between revisions
Content deleted Content added
→{{header|PARI/GP}}: output formatting |
|||
Line 2,213: | Line 2,213: | ||
Farey sequence fractions, 100 to 1000 by hundreds: |
Farey sequence fractions, 100 to 1000 by hundreds: |
||
{3045,12233,27399,48679,76117,109501,149019,194751,246327,304193} |
{3045,12233,27399,48679,76117,109501,149019,194751,246327,304193} |
||
</pre> |
|||
=={{header|Picat}}== |
|||
<lang Picat>go ?=> |
|||
member(N,1..11), |
|||
Farey = farey(N), |
|||
println(N=Farey), |
|||
fail, |
|||
nl. |
|||
go => true. |
|||
farey(N) = M => |
|||
M1 = [0=$(0/1)] ++ |
|||
[I2/J2=$(I2/J2) : I in 1..N, J in I..N, |
|||
GCD=gcd(I,J),I2 =I//GCD,J2=J//GCD].sort_remove_dups(), |
|||
M = [ E: _=E in M1]. % extract the rational representation |
|||
</lang> |
|||
Output: |
|||
<pre>1 = [0 / 1,1 / 1] |
|||
2 = [0 / 1,1 / 2,1 / 1] |
|||
3 = [0 / 1,1 / 3,1 / 2,2 / 3,1 / 1] |
|||
4 = [0 / 1,1 / 4,1 / 3,1 / 2,2 / 3,3 / 4,1 / 1] |
|||
5 = [0 / 1,1 / 5,1 / 4,1 / 3,2 / 5,1 / 2,3 / 5,2 / 3,3 / 4,4 / 5,1 / 1] |
|||
6 = [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] |
|||
7 = [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] |
|||
8 = [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] |
|||
9 = [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] |
|||
10 = [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] |
|||
11 = [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] |
|||
</pre> |
|||
The number of fractions of order 100..100..1000: |
|||
<lang Picat>go2 => |
|||
foreach(N in 100..100..1000) |
|||
F = farey(N), |
|||
println(N=F.length) |
|||
end, |
|||
nl.</lang> |
|||
Output: |
|||
<pre>100 = 3045 |
|||
200 = 12233 |
|||
300 = 27399 |
|||
400 = 48679 |
|||
500 = 76117 |
|||
600 = 109501 |
|||
700 = 149019 |
|||
800 = 194751 |
|||
900 = 246327 |
|||
1000 = 304193 |
|||
</pre> |
</pre> |
||