Guest User

Untitled

a guest
Feb 14th, 2018
17
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static void Main(string[] args)
  2. {
  3. char[] arAlphabet = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; // используемый алфавит
  4. int n = 20; // количество мест в комбинации
  5. char[] arBuffer = new char[n];
  6. string fileName = "ResultGenerate.txt";
  7.  
  8. StreamWriter writer = File.CreateText(fileName); // файл при каждом запуске должен создаваться заново
  9. writer.Close();
  10.  
  11. StringBuilder stringBuilder = new StringBuilder((int)Math.Pow(arAlphabet.Length, n) * (n + 2));
  12. RecursionGenerateCombinationsToFile(arAlphabet, arBuffer, 0, fileName, stringBuilder);
  13. }
  14.  
  15. // Рекурсивный медод
  16. static int count = 0;
  17. static int allcount = 0;
  18. static void RecursionGenerateCombinationsToFile(char[] arAlphabet, char[] arBuffer, int order, string fileName, StringBuilder stringBuilder)
  19. {
  20. if (order < arBuffer.Length)
  21. for (int i = 0; i < arAlphabet.Length; i++)
  22. {
  23. arBuffer[order] = arAlphabet[i];
  24. RecursionGenerateCombinationsToFile(arAlphabet, arBuffer, order + 1, fileName, stringBuilder);
  25. }
  26. else
  27. {
  28.  
  29. for (int i = 0; i < arBuffer.Length; i++)
  30. stringBuilder.Append(arBuffer[i]);
  31. stringBuilder.AppendLine();
  32. count++;
  33.  
  34. if (count > 500000)
  35. {
  36.  
  37. StreamWriter writer = File.AppendText($"ResultGenerate{allcount}.txt" );
  38. writer.Write(stringBuilder.ToString());
  39. writer.Close();
  40. count = 0;
  41. stringBuilder.Clear();
  42. allcount++;
  43. }
  44. }
  45. }
RAW Paste Data