H6X9H


Analysis

A recipe can be decomposed in one or more chunks RpLq, where Rp denotes p times direction R and Lq denotes q times direction L. The values p and q depend on the input numbers N and D. Define the characteristic equation N = K*D + E, where K > 0 and 0 < E < D .

3 situations can be discerned

a)      2*N = (2*K+1) * D

So, D = 2*E and N = (2*K+1)*E . Since N and D are relatively prime, the value of E must be 1, and hence D=2. The corresponding recipe, equal to R(N+1)/2 L(N-1)/2 has a primitive structure.

b)      2*N < (2*K+1) * D

This situation is equivalent to E < D/2. The chunks look like RK+1 LK , or RK LK+1, or RK LK . Their multiplicities can be derived by comparing multiples of D with the boundaries N and 2*N . The values of the multiplicities are respectively (E+1)/2, (E-1)/2, and (D/2-E) .

c)      2*N > (2*K+1) * D

In this situation, equivalent to E > D/2, the chunks look slightly different, namely RK+1 LK+1, or RK+1 LK , or RK LK+1 . For simplifying the formulas we introduce the variable F := D-E . The multiplicities of the chunks are then respectively (D/2-F), (F+1)/2, and (F-1)/2 .

For all 3 situations can be easily verified that the recipe contains N directions, and that the number of R directions is 1 more than the number of L directions.