я нашел решение здесь: https://www.geeksforgeeks.org/print-all-combinations-of-given-length /
Надеялся, что оно ты функционирует, Привет!
using System;
namespace Tests
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("First Test");
int[] set1 = { 1, 2, 3 };
int k = 3;
printAllKLength(set1, k);
Console.WriteLine("\nSecond Test");
int[] set2 = { 1, 2, 3, 4 };
k = 2;
printAllKLength(set2, k);
Console.ReadLine();
}
// The method that prints all
// possible strings of length k.
// It is mainly a wrapper over
// recursive function printAllKLengthRec()
static void printAllKLength(int[] set, int k)
{
int n = set.Length;
printAllKLengthRec(set, "", n, k);
}
// The main recursive method
// to print all possible
// strings of length k
static void printAllKLengthRec(int[] set,
String prefix,
int n, int k)
{
// Base case: k is 0,
// print prefix
if (k == 0)
{
Console.WriteLine(prefix);
return;
}
// One by one add all characters
// from set and recursively
// call for k equals to k-1
for (int i = 0; i < n; ++i)
{
// Next character of input added
String newPrefix = prefix + set[i];
// k is decreased, because
// we have added a new character
printAllKLengthRec(set, newPrefix,
n, k - 1);
}
}
}
}