Skip to main content
deleted 12 characters in body
Source Link

Python 3, 98 83 bytes

f=lambda a,b,n=1,d=2:a>b and f(a-b,b,n*2+1,d*2)or a<b and f(a,b-a,n*2-1,d*2)or(n,d) 

Try it online!

Explanation: The sequence of turns starting from 1 down to the given fraction in the Stern-Brocot tree is identical to the sequence of turns starting from the given fraction going to 1 in the Calkin-Wilf tree. This makes it much simpler to get the sequence.

Improvement given by Bubbler's golf tipsBubbler. Original solution here.

Python 3, 98 83 bytes

f=lambda a,b,n=1,d=2:a>b and f(a-b,b,n*2+1,d*2)or a<b and f(a,b-a,n*2-1,d*2)or(n,d) 

Try it online!

Explanation: The sequence of turns starting from 1 down to the given fraction in the Stern-Brocot tree is identical to the sequence of turns starting from the given fraction going to 1 in the Calkin-Wilf tree. This makes it much simpler to get the sequence.

Improvement given by Bubbler's golf tips. Original solution here.

Python 3, 98 83 bytes

f=lambda a,b,n=1,d=2:a>b and f(a-b,b,n*2+1,d*2)or a<b and f(a,b-a,n*2-1,d*2)or(n,d) 

Try it online!

Explanation: The sequence of turns starting from 1 down to the given fraction in the Stern-Brocot tree is identical to the sequence of turns starting from the given fraction going to 1 in the Calkin-Wilf tree. This makes it much simpler to get the sequence.

Improvement given by Bubbler. Original solution here.

Giving credit.
Source Link

Python 3, 9898 83 bytes

deff=lambda f(a,b,n=1,d=2):  a>b whileand f(a!=b-b,b,n*2+1,d*2): or n*=2;d*=2 a<b and iff(a>b):a,n=a-b,n+1 else:b,n=b-a,nn*2-1 return ,d*2)or(n,d) 

Try it online!Try it online!

Explanation: The sequence of turns starting from 1 down to the given fraction in the Stern-Brocot tree is identical to the sequence of turns starting from the given fraction going to 1 in the Calkin-Wilf tree. This makes it much simpler to get the sequence.

Improvement given by Bubbler's golf tips. Original solution here.

Python 3, 98 bytes

def f(a,b,n=1,d=2):   while(a!=b):  n*=2;d*=2  if(a>b):a,n=a-b,n+1 else:b,n=b-a,n-1 return n,d 

Try it online!

Explanation: The sequence of turns starting from 1 down to the given fraction in the Stern-Brocot tree is identical to the sequence of turns starting from the given fraction going to 1 in the Calkin-Wilf tree. This makes it much simpler to get the sequence.

Python 3, 98 83 bytes

f=lambda a,b,n=1,d=2:a>b and f(a-b,b,n*2+1,d*2)or a<b and f(a,b-a,n*2-1,d*2)or(n,d) 

Try it online!

Explanation: The sequence of turns starting from 1 down to the given fraction in the Stern-Brocot tree is identical to the sequence of turns starting from the given fraction going to 1 in the Calkin-Wilf tree. This makes it much simpler to get the sequence.

Improvement given by Bubbler's golf tips. Original solution here.

Source Link

Python 3, 98 bytes

def f(a,b,n=1,d=2): while(a!=b): n*=2;d*=2 if(a>b):a,n=a-b,n+1 else:b,n=b-a,n-1 return n,d 

Try it online!

Explanation: The sequence of turns starting from 1 down to the given fraction in the Stern-Brocot tree is identical to the sequence of turns starting from the given fraction going to 1 in the Calkin-Wilf tree. This makes it much simpler to get the sequence.