Exemple #1
0
    public static void Test02a()
    {
        PartitionSet ps = new PartitionSet(3);

        // add partitions of number 3 manually
        Partition p;

        p = new Partition(new int[] { 3 });
        ps.Insert(p);
        p = new Partition(new int[] { 1, 2 });
        ps.Insert(p);
        p = new Partition(new int[] { 1, 1, 1 });
        ps.Insert(p);
        Console.WriteLine(ps);
    }
Exemple #2
0
    public static void Test02b()
    {
        PartitionSet ps = new PartitionSet(3);

        // add partitions of number 3 manually
        // (note order of 'Insert' calls)
        Partition p;

        p = new Partition(new int[] { 1, 1, 1 });
        ps.Insert(p);
        p = new Partition(new int[] { 2, 1 });
        ps.Insert(p);
        p = new Partition(new int[] { 3 });
        ps.Insert(p);
        ps.SortDescending();    // sorting partitions
        Console.WriteLine(ps);
    }
Exemple #3
0
    public static void Test05()
    {
        PartitionSet ps = new PartitionSet(2);

        // add partitions of number 2 manually
        Partition p;

        p = new Partition(new int[] { 2 });
        ps.Insert(p);
        p = new Partition(new int[] { 1, 1 });
        ps.Insert(p);
        Console.WriteLine("Partitions of {0}:", ps.Number);
        for (int i = 0; i < ps.Count; i++)
        {
            p = ps[i];
            Console.WriteLine(p);
        }
    }
Exemple #4
0
    public static PartitionSet Calculate(int number)
    {
        PartitionSet result = new PartitionSet(number);

        if (number == 1)
        {
            Partition p = new Partition(new int[] { 1 });
            result.Insert(p);
        }
        else
        {
            PartitionSet setMinusOne = Calculate(number - 1);

            for (int i = 0; i < setMinusOne.Count; i++)
            {
                int[] numbers = setMinusOne[i].Numbers;

                for (int j = 0; j < numbers.Length; j++)
                {
                    numbers[j]++;
                    Partition p = new Partition(numbers);
                    result.Insert(p);
                    numbers[j]--;
                }
            }

            // create missing partition (just consisting of '1's)
            int[] partitionOnes = new int[number];
            for (int k = 0; k < partitionOnes.Length; k++)
            {
                partitionOnes[k] = 1;
            }

            Partition pOnes = new Partition(partitionOnes);
            result.Insert(pOnes);
        }
        return(result);
    }