Return the nth rational number.
The first ten positive rational numbers under the enumeration using cantors diagonalization argument are 1/1, 2/1, 1/2, 3/1, 2/2, 1/3, 4/1, 3/2, 2/3, 1/4.
Find the index of a positive rational number enumerated in this manner, i.e. the 6th rational number is 1/3.
Solution Stats
Problem Comments
2 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers171
Suggested Problems
-
Determine whether a vector is monotonically increasing
22847 Solvers
-
2366 Solvers
-
1742 Solvers
-
Back to basics 20 - singleton dimensions
275 Solvers
-
Output any real number that is neither positive nor negative
408 Solvers
More from this Author10
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Is that possible to have a ranking of the solutions based on their performing time? I think that the could be a method that is fast even if more sized.
Solution
provides inexpensive method. There is only one 2nd order polynomial solution and one division.