class ComplexValue
{
const string m_Alphabet = "abcdefghijklmnopqrstuvwxyz";
int First { get; set; }
char[] Middle { get; set; };
int Last { get; set; }
public ComplexValue(string input)
{
First = int.Parse(input.Substring(0, 1));
Middle = input.Substring(1, 3).ToCharArray();
Last = int.Parse(input.Substring(input.Length - 1, 1));
}
public string Value() => $"{First}{new string(Middle)}{Last}";
private int IncrementLast()
{
Last++;
if (Last > 9) { Last = 0; return 1; }
return 0;
}
private int DecrementLast()
{
Last--;
if (Last < 0) { Last = 9; return 1 }
return 0;
}
private char IncrementChar(char c, out bool carry)
{
carry = false;
c++;
if (c > m_Alphabet[m_Alphabet.Length -1] )
{
c = m_Alphabet[0];
carry = true;
}
return c;
}
private char DecrementChar(char c, out bool borrow)
{
borrow = false;
c--;
if (c < m_Alphabet[0])
{
c = m_Alphabet[m_Alphabet.Length - 1];
borrow = true;
}
return c;
}
private int IncrementMiddle()
{
int pos = Middle.Length - 1;
while (pos > 0)
{
Middle[pos] = IncrementChar(Middle[pos], out bool carry);
if (!carry) return 0;
pos--;
}
return 1;
}
private int DecrementMiddle()
{
int pos = Middle.Length - 1;
while (pos > 0)
{
Middle[pos] = DecrementChar(Middle[pos], out bool borrow);
if (!borrow) return 0;
pos--;
}
return 1;
}
public void Increment()
{
if (IncrementLast() > 0)
{
if (IncrementMiddle() > 0) First++;
}
}
public void Decrement()
{
if (DecrementLast() > 0)
{
if (DecrementMiddle() > 0) First--;
}
}
}
static void Main(string[] args)
{
var start = "1abc3";
GetCascading(start, 6);
}
static string[] GetCascading(string val, int count)
{
var result = new List<string>();
var intVal = int.Parse(val, System.Globalization.NumberStyles.HexNumber);
for (var i = 1; i < count + 1; i++) result.Add((intVal - i).ToString("X"));
return result.ToArray();
}