Find a fraction's position in the Stern-Brocot tree
Ruby, 132 125

Rubied &amp; golfed the reference solution from @JoeZ.

def t(n,d)u=k=0;v,j,f,g,b=[1,]*5;c=2
while(z=(f*d).&lt;=&gt;(g*n))!=0;z&gt;0?(j,k=f,g):(u,v=f,g);b=b*2-z;f,g=u+j,v+k;c*=2;end
[b,c]end


Usage examples:

&gt;&gt; t(2,3)
=&gt; [3, 8]
&gt;&gt; t(4,7)
=&gt; [9, 32]
&gt;&gt; t(1,1)
=&gt; [1, 2]