How to resolve the algorithm Farey sequence step by step in the Racket programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Farey sequence step by step in the Racket 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 Racket programming language
Source code in the racket programming language
#lang racket
(require math/number-theory)
(define (display-farey-sequence order show-fractions?)
(define f-s (farey-sequence order))
(printf "-- Farey Sequence for order ~a has ~a fractions~%" order (length f-s))
;; racket will simplify 0/1 and 1/1 to 0 and 1 respectively, so deconstruct into numerator and
;; denomimator (and take the opportunity to insert commas
(when show-fractions?
(displayln
(string-join
(for/list ((f f-s))
(format "~a/~a" (numerator f) (denominator f)))
", "))))
; compute and show the Farey sequence for order:
; 1 through 11 (inclusive).
(for ((order (in-range 1 (add1 11)))) (display-farey-sequence order #t))
; compute and display the number of fractions in the Farey sequence for order:
; 100 through 1,000 (inclusive) by hundreds.
(for ((order (in-range 100 (add1 1000) 100))) (display-farey-sequence order #f))
You may also check:How to resolve the algorithm Pythagoras tree step by step in the Nim programming language
You may also check:How to resolve the algorithm Fibonacci word/fractal step by step in the Phix programming language
You may also check:How to resolve the algorithm Day of the week step by step in the bc programming language
You may also check:How to resolve the algorithm Date format step by step in the R programming language
You may also check:How to resolve the algorithm Time a function step by step in the BaCon programming language