static public void generate_Permutations(string[] source) //TODO: disconnect proccess of generating combinations from calls to permutation algorithm to enable farther work distribution between threeds + feature(ignore part of combinations) { CheckParams(source); string path = $@"CombinationList_{DateTime.Now.ToString("yyyyMMddHHmmss")}.txt"; Permutations_Vault p_vault = new Permutations_Vault(path); permutation_algorithm(source, 0, source.Length - 1, p_vault); for (int k = 1; k <= source.Length - 1; k++) { for (int i = 0; i <= source.Length - 1; i++) { string[] particularCombination; prepCombination(out particularCombination, source, k, i); permutation_algorithm(particularCombination, 0, particularCombination.Length - 1, p_vault); p_vault.dumpIfNecessary(); } } }
static private void permutation_algorithm(string[] s, int i, int n, Permutations_Vault vault) { if (i == n) { vault.store_result(s); Counter++; } else { for (int j = i; j <= n; j++) { string tmp = s[j]; s[j] = s[i]; s[i] = tmp; permutation_algorithm(s, i + 1, n, vault); tmp = s[j]; s[j] = s[i]; s[i] = tmp; } } }