Skip to content

2015-3: Farey Tale

In mathematics, the Farey_sequence 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. Each Farey sequence starts with the value 0, denoted by the fraction 01, and ends with the value 1, denoted by the fraction 11.

Write a function that takes an integer right argument and returns a vector of the terms in the Farey sequence of that order. Each element in the returned vector is itself a 2-element vector of numerator and denominator for the corresponding term.

Examples:

     (your_function) 0 
┌───┐
│0 1│
└───┘
     (your_function) 1
┌───┬───┐
│0 1│1 1│
└───┴───┘
     (your_function) 5
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
│0 1│1 5│1 4│1 3│2 5│1 2│3 5│2 3│3 4│4 5│1 1│
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
your_function ←

Solutions

Video Thumbnail YouTube

Chat transcript Code on GitHub