This is an extended comment, and should give you an answer to your first question.
If you are fine with your current code style, I did find a setting of your priority of Shortest
and Longest
that gives you the expected result. So here they are:
RealDigits[99/700, 10, 24][[1]]/. {Shortest[pre___, 3],
Longest[Repeated[Shortest[r__Longest[Repeated[Shortest[rep__, 1], {2, Infinity}]],
Shortest[inc___, 2]} /;
MatchQ[{rrep}, {inc, __}] :> {{pre}, {rrep}, {inc}})
In my experiments, I found that the priority of Shortest
and Longest
is not related, so the setting for Longest
can be removed. If you are curious why I have this conclusion, here is the list of "full" parameters I found:
{{3, 1, 4, 2}, {4, 1, 2, 3}, {4, 1, 3, 2}, {4, 2, 1, 3}}
The third argument is for Longest
, and clearly its priority does not matter.
Also, I think {2, Infinity}
in your Repeat
can't be omitted, otherwise the program tends to regard the whole sequence as the recurring period.
I didn't explore further into this problem or fully tested the settings, so I am not sure how well it can generalize.