From Wikipedia:
In number theory, the Calkin–Wilf tree is a tree in which the vertices correspond one-to-one to the positive rational numbers. The tree is rooted at the number \$1\$, and any rational number expressed in simplest terms as the fraction \$\frac{a}{b}\$ has as its two children the numbers \$\frac{a}{a+b}\$ and \$\frac{a+b}{b}\$.
The Calkin–Wilf sequence is the sequence of rational numbers generated by a breadth-first traversal of the Calkin–Wilf tree, $$\frac11, \frac12, \frac21, \frac13, \frac32, \frac23, \frac31, \frac14, \frac43, \frac35, \frac52, \ldots$$
For this challenge, you are given a fraction found in the \$i\$th position of the Calkin-Wilf sequence, and must output \$i\$. You can start from either 0 or 1.
Test cases
(Starting from 1.)
\$a_i\$ | \$i\$ |
---|---|
\$\frac11\$ | \$1\$ |
\$\frac13\$ | \$4\$ |
\$\frac43\$ | \$9\$ |
\$\frac34\$ | \$14\$ |
\$\frac{53}{37}\$ | \$1081\$ |
\$\frac{37}{53}\$ | \$1990\$ |
Standard loopholes are forbidden. Since this is code-golf, the shortest code wins.