예제 #1
0
        private void PermutateWords()
        {
            var words = _rgxWords.Split(txtInput.Text.Trim());
            var fromN = words.Length;

            if (fromN > 7)
            {
                txtOutput.Text = "Many permutations requested - may take some time...";
                txtOutput.Refresh();
            }
            if (fromN > 9)
            {
                MessageBox.Show("avoid to input more than 9 Word - Richtextbox has Trouble to display millions of results ( eg 10! = 3.628.800 )");
                return;
            }
            var wordCounts    = words.GroupBy(w => w, w => 2, (g, w) => w.Count());
            var indexCounter  = 0;
            var indicees      = wordCounts.SelectMany(cnt => Enumerable.Repeat(indexCounter++, cnt));
            var distinctWords = words.Distinct().ToArray();
            var sb            = new StringBuilder();
            var counter       = 0;

            foreach (var result in Combinatorics.Permutation(indicees))
            {
                sb.AppendLine(string.Join(" ", result.Select(i => distinctWords[i])));
                counter += 1;
            }
            txtOutput.Text = string.Concat("Permutating the given set of word yields: ", counter, " results\n\n", sb.ToString());
        }
예제 #2
0
        private static void CompareChooseKfromN(int chooseK, int fromN, CombinatoricMode mode)
        {
            var tst1 = Combinatorics.ChooseKfromN(chooseK, fromN, mode).ToArray();
            var tst2 = Combinatorics.ChooseKfromN(chooseK, fromN, mode); // enter alternative-call here

            Compare(tst1, tst2);
        }
예제 #3
0
        private void ApplyNumeric(int chooseK, int fromN, CombinatoricMode mode)
        {
            var sb      = new StringBuilder();
            var counter = 0;

            foreach (var result in Combinatorics.ChooseKfromN(chooseK, fromN, mode))
            {
                sb.Append(string.Concat(result)).Append(" ");
                counter += 1;
            }
            txtOutput.Text = string.Concat(Preambel(chooseK, fromN, mode), counter, " results\n\n", sb.ToString());
        }
예제 #4
0
        private void Apply2Words(int chooseK, int fromN, CombinatoricMode mode)
        {
            //demo, how to transform the int-results to any other DataType: Just take them as Indicees of an Source-Element-Array (of any type).
            var sb    = new StringBuilder();
            var words = _rgxWords.Split(txtInput.Text.Trim());

            if (words.Length != fromN)
            {
                MessageBox.Show("number of words must equal the fromN-Parameter");
                return;
            }
            var counter = 0;

            foreach (var result in Combinatorics.ChooseKfromN(chooseK, fromN, mode))
            {
                sb.AppendLine(string.Join(" ", result.Select(i => words[i]).ToArray()));
                counter += 1;
            }
            txtOutput.Text = string.Concat(Preambel(chooseK, fromN, mode), counter, " results\n\n", sb.ToString());
        }
예제 #5
0
 private static void ComparePermutations(IEnumerable <int> ints)// enter alternative-call here
 {
     Compare(Combinatorics.Permutation(ints.ToArray()), Combinatorics.Permutation(ints.ToArray()));
 }