I hovered over such a question, to put the interval from and to , like this:

class Program { static void Main(string[] args) { string alfavit = "abc"; for (int a = 0; a < alfavit.Length; a++) { string start_pos = "cb"; string end_pos = "cd"; string main = start_pos + alfavit[a].ToString(); Console.WriteLine(main); if (main == end_pos) { Console.WriteLine(main); } main = end_pos + alfavit[a].ToString(); Console.WriteLine(main); if (main == end_pos) { Console.WriteLine(main); } } Console.ReadKey(); } } 

}

How to get the computer to show like this on the screen: cba cbb cbc cca ccb ccc cda cda cda

  • 2
    cda cda cda ? o_O - Qwertiy
  • Tipo combinations of all options? - Vadim Prokopchuk February

1 answer 1

There are many different ways. The classic way is to establish the correspondence between your string and the number in the n -thick notation (for your case, n == 3 ). I will show a simpler from the ideological point of view option that simulates the transition to the next line. For convenience, I will use character arrays.

 class Alphabet { int size; List<char> letters; Dictionary<char, int> indices; public Alphabet(IEnumerable<char> letters) { this.letters = letters.ToList(); this.indices = this.letters.Select((c, idx) => new { c, idx }) .ToDictionary(p => pc, p => p.idx); this.size = this.letters.Count; } public bool Advance(ref char c) { var letterPos = indices[c] + 1; if (letterPos == size) letterPos = 0; c = letters[letterPos]; return letterPos > 0; } public bool Advance(char[] chars) { for (int index = chars.Length - 1; index >= 0; index--) { if (Advance(ref chars[index])) return true; } return false; } } 

Having such an auxiliary class, you can do different things. For example, the output of all lines:

 var abc = new Alphabet("abc"); var chars = "aaa".ToCharArray(); do { Console.WriteLine(new string(chars)); } while (abc.Advance(chars)); 

The output lines from "bac" to "cab" :

 var chars2 = "bac".ToCharArray(); do { var s = new string(chars2); Console.WriteLine(s); if (s == "cab") break; } while (abc.Advance(chars2)); 

etc.