11
1
Create a function that takes a natural number (starting from 0 inclusive), and returns a pair of positive integers, which are the numerator and denominator respectively. Use the diagonal traversal. Previous-counted numbers must be skipped. (you can memorize the set of skipped values)
Diagram:
Red are skipped values
Values:
- f(0) = 1, 1
- f(1) = 2, 1
- f(2) = 1, 2
- f(3) = 1, 3
- f(4) = 3, 1 (notice the skip)
- f(5) = 4, 1
- f(6) = 3, 2
- f(7) = 2, 3
- f(8) = 1, 4
- f(9) = 1, 5
- f(10) = 5, 1 (notice the skip)
You may use the Rational data structure and their operations if they exist. Shortest code wins.
1The number of counted rational numbers in each diagonal is the totient function of that diagonal's common sum. – Leaky Nun – 2016-08-11T15:49:51.653
I know this challenge is old, but there exists a shorter answer than the accepted one, so you might want to re-accept. – Esolanging Fruit – 2017-11-03T04:19:16.383