Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Farey-sequence/Racket/farey-sequence.rkt
Normal file
20
Task/Farey-sequence/Racket/farey-sequence.rkt
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#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))
|
||||
Loading…
Add table
Add a link
Reference in a new issue