How to resolve the algorithm Farey sequence step by step in the Ring programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Farey sequence step by step in the Ring 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 Ring programming language
Source code in the ring programming language
# Project : Farey sequence
for i = 1 to 11
count = 0
see "F" + string(i) + " = "
farey(i, false)
next
see nl
for x = 100 to 1000 step 100
count = 0
see "F" + string(x) + " = "
see farey(x, false)
see nl
next
func farey(n, descending)
a = 0
b = 1
c = 1
d = n
if descending = true
a = 1
c = n -1
ok
count = count + 1
if n < 12
see string(a) + "/" + string(b) + " "
ok
while ((c <= n) and not descending) or ((a > 0) and descending)
aa = a
bb = b
cc = c
dd = d
k = floor((n + b) / d)
a = cc
b = dd
c = k * cc - aa
d = k * dd - bb
count = count + 1
if n < 12
see string(a) + "/" + string(b) + " "
ok
end
if n < 12
see nl
ok
return count
You may also check:How to resolve the algorithm HTTPS step by step in the Frink programming language
You may also check:How to resolve the algorithm Call a function step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Create an object at a given address step by step in the PureBasic programming language
You may also check:How to resolve the algorithm 100 doors step by step in the Crystal programming language
You may also check:How to resolve the algorithm HTTP step by step in the EchoLisp programming language