/// <summary> /// Constructs sub-automaton corresponding to decimal numbers of value between x.Substring(n) /// and y.Substring(n) and of length x.Substring(n).Length (which must be equal to /// y.Substring(n).Length). /// </summary> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <param name="n">The n.</param> /// <param name="initials">The initials.</param> /// <param name="zeros">if set to <c>true</c> [zeros].</param> /// <returns></returns> private static State Between(string x, string y, int n, ICollection <State> initials, bool zeros) { var s = new State(); if (x.Length == n) { s.Accept = true; } else { if (zeros) { initials.Add(s); } char cx = x[n]; char cy = y[n]; if (cx == cy) { s.AddTransition(new Transition(cx, Between(x, y, n + 1, initials, zeros && cx == '0'))); } else { // cx < cy s.AddTransition(new Transition(cx, BasicAutomata.AtLeast(x, n + 1, initials, zeros && cx == '0'))); s.AddTransition(new Transition(cy, BasicAutomata.AtMost(y, n + 1))); if (cx + 1 < cy) { s.AddTransition(new Transition((char)(cx + 1), (char)(cy - 1), BasicAutomata.AnyOfRightLength(x, n + 1))); } } } return(s); }