// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; class Perm { public static void WriteRecursive(string[] s, string prefix, int ix, int len) { if(ix < len) { for(int i = 0; i < s.Length; i++) { WriteRecursive(s, prefix + s[i], ix + 1, len); } } else { Console.WriteLine(prefix); } } public static void WritePerm(string[] s, int len) { WriteRecursive(s, "", 0, len); } public static void Main(string[] args) { Console.Write("Indtast antal mulige tegn: "); int n = int.Parse(Console.ReadLine()); string[] s = new string[n]; for(int i = 0; i < n; i++) { Console.Write("Indtast tegn " + i + ": "); s[i] = Console.ReadLine(); } Console.Write("Indtast antal tegn i kombinationer: "); int len = int.Parse(Console.ReadLine()); WritePerm(s, len); } }