Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void Main(string[] args)
- {
- char[] arAlphabet = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; // используемый алфавит
- int n = 20; // количество мест в комбинации
- char[] arBuffer = new char[n];
- string fileName = "ResultGenerate.txt";
- StreamWriter writer = File.CreateText(fileName); // файл при каждом запуске должен создаваться заново
- writer.Close();
- StringBuilder stringBuilder = new StringBuilder((int)Math.Pow(arAlphabet.Length, n) * (n + 2));
- RecursionGenerateCombinationsToFile(arAlphabet, arBuffer, 0, fileName, stringBuilder);
- }
- // Рекурсивный медод
- static int count = 0;
- static int allcount = 0;
- static void RecursionGenerateCombinationsToFile(char[] arAlphabet, char[] arBuffer, int order, string fileName, StringBuilder stringBuilder)
- {
- if (order < arBuffer.Length)
- for (int i = 0; i < arAlphabet.Length; i++)
- {
- arBuffer[order] = arAlphabet[i];
- RecursionGenerateCombinationsToFile(arAlphabet, arBuffer, order + 1, fileName, stringBuilder);
- }
- else
- {
- for (int i = 0; i < arBuffer.Length; i++)
- stringBuilder.Append(arBuffer[i]);
- stringBuilder.AppendLine();
- count++;
- if (count > 500000)
- {
- StreamWriter writer = File.AppendText($"ResultGenerate{allcount}.txt" );
- writer.Write(stringBuilder.ToString());
- writer.Close();
- count = 0;
- stringBuilder.Clear();
- allcount++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement