Farey sequence: Difference between revisions
Content added Content deleted
Langurmonkey (talk | contribs) |
Langurmonkey (talk | contribs) |
||
Line 2,201: | Line 2,201: | ||
=={{header|langur}}== |
=={{header|langur}}== |
||
<syntaxhighlight lang="langur"> |
<syntaxhighlight lang="langur"> |
||
val farey = fn(n) { |
|||
var .a, .b, .c, .d = 0, 1, 1, .n |
|||
var a, b, c, d = 0, 1, 1, n |
|||
while[=[[0, 1]]] c <= n { |
|||
val k = (n + b) // d |
|||
a, b, c, d = c, d, k * c - a, k * d - b |
|||
_while ~= [[a, b]] |
|||
} |
} |
||
} |
} |
||
val |
val testFarey = impure fn() { |
||
writeln "Farey sequence for orders 1 through 11" |
writeln "Farey sequence for orders 1 through 11" |
||
for |
for i of 11 { |
||
writeln "{{ |
writeln "{{i:2}}: ", join(" ", map(fn f: "{{f[1]}}/{{f[2]}}", farey(i))) |
||
} |
|||
} |
} |
||
testFarey() |
|||
writeln() |
writeln() |
||
writeln "count of Farey sequence fractions for 100 to 1000 by hundreds" |
writeln "count of Farey sequence fractions for 100 to 1000 by hundreds" |
||
for |
for i = 100; i <= 1000; i += 100 { |
||
writeln |
writeln "{{i:4}}: ", len(farey(i)) |
||
} |
|||
</syntaxhighlight> |
|||
{{out}} |
{{out}} |