Farey sequence: Difference between revisions

(Added QBasic)
 
(3 intermediate revisions by the same user not shown)
Line 2,201:
 
=={{header|langur}}==
<syntaxhighlight lang="langur">val .farey = fn(.n) {
val farey = fn(n) {
var .a, .b, .c, .d = 0, 1, 1, .n
while[=[[0var a, 1]]]b, .c, d <= .n0, {1, 1, n
while[=[[0, 1]]] c val .k <= (.n + .b) // .d{
.a,val .b, .c, .dk = .c,(n .d,+ .kb) *// .c - .a, .k * .d - .b
_whilea, b, c, d ~= [[.c, d, k * c - a, .k * d - b]]
_while ~= [[a, b]]
}
}
 
val .testFarey = impure fn*() {
writeln "Farey sequence for orders 1 through 11"
for .i of 11 {
writeln $"\.{{i:2;}}: ", join (" ", map(fn(. f): $"\.{{f[1];}}/\.{{f[2];}}", .farey(.i)))
}
}
 
.testFarey()
 
writeln()
writeln "count of Farey sequence fractions for 100 to 1000 by hundreds"
for .i = 100; .i <= 1000; .i += 100 {
writeln $"\.{{i:4;}}: ", len(.farey(.i))
}
}</syntaxhighlight>
 
{{out}}
1,007

edits