Analysis

A recipe can
be
decomposed in one or more chunks R^{p}L^{q},
where R^{p}
denotes p times direction R and L^{q} 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

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.

This
situation is equivalent to E
< D/2. The chunks look like R^{K+1} L^{K}
, or R^{K}
L^{K+1}, or R^{K} L^{K}
. 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) .

In
this situation, equivalent to E
> D/2, the chunks look slightly different, namely R^{K+1}
L^{K+1},
or R^{K+1} L^{K} , or R^{K}
L^{K+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.