How to resolve the algorithm Farey sequence step by step in the langur programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Farey sequence step by step in the langur programming language

Table of Contents

Problem Statement

The   Farey sequence   Fn   of order   n   is the sequence of completely reduced fractions between   0   and   1   which, when in lowest terms, have denominators less than or equal to   n,   arranged in order of increasing size. The   Farey sequence   is sometimes incorrectly called a   Farey series.

Each Farey sequence:

The Farey sequences of orders   1   to   5   are:

The length   (the number of fractions)   of a Farey sequence asymptotically approaches:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Farey sequence step by step in the langur programming language

Source code in the langur programming language

val .farey = f(.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 x .c - .a, .k x .d - .b
        _while ~= [[.a, .b]]
    }
}

val .testFarey = f() {
    writeln "Farey sequence for orders 1 through 11"
    for .i of 11 {
        writeln $"\.i:2;: ", join " ", map(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))
}

  

You may also check:How to resolve the algorithm Primes - allocate descendants to their ancestors step by step in the Simula programming language
You may also check:How to resolve the algorithm Rosetta Code/Rank languages by popularity step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Classes step by step in the Arturo programming language
You may also check:How to resolve the algorithm Farey sequence step by step in the Quackery programming language
You may also check:How to resolve the algorithm Binary digits step by step in the Factor programming language