Solution of the Week #363 - Zero to Pi(ish)

The easiest thing is to do the whole procedure in reverse. Action a then become x-1 (action b is unchanged).

So starting with a rational number, to get to 0 in the fewest steps, whenever your number is greater than or equal to 1, perform action a and whenever your number is less than 1, perform action b.

In other words, each time the numerator is less than the denominator, flip the fraction upside down, and in doing so you will successively reduce the denominator until it is 1 and you can then keep subtracting until you get to zero.

 

From 355/113 to 0 will take a total of 28 actions:

 

355/113 = 3 16/113

a, 3 times

16/113

b

113/16 = 7 1/16

a, 7 times

1/16

b

16

a, 16 times

0

 

Reversing the process to go from 0 to 355/133 will clearly also take 28 actions: 16a,b,7a,b,3a.