public static void pentagon_num_test( )

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    PENTAGON_NUM_TEST tests PENTAGON_NUM.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 June 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int n;

        Console.WriteLine("");
        Console.WriteLine("PENTAGON_NUM_TEST");
        Console.WriteLine("  PENTAGON_NUM computes the pentagonal numbers.");
        Console.WriteLine("");

        for (n = 1; n <= 10; n++)
        {
            Console.WriteLine("  " + n.ToString().PadLeft(4)
                              + "  " + Pentagon.pentagon_num(n).ToString().PadLeft(6) + "");
        }
    }
    public static void pent_enum_test( )

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    PENT_ENUM_TEST tests PENT_ENUM.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    07 March 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int N = 10;

        int i;

        Console.WriteLine("");
        Console.WriteLine("PENT_ENUM_TEST");
        Console.WriteLine("  PENT_ENUM counts points in pentagons.");
        Console.WriteLine("");
        Console.WriteLine("   N  Pent(N)");
        Console.WriteLine("");

        for (i = 0; i <= N; i++)
        {
            Console.WriteLine(i.ToString().PadLeft(4) + "  "
                              + Pentagon.pentagon_num(i).ToString().PadLeft(6) + "");
        }
    }
Exemple #3
0
    public static void i4_partition_count(int n, ref int[] p)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    I4_PARTITION_COUNT computes the number of partitions of an integer.
    //
    //  Discussion:
    //
    //    Partition numbers are difficult to compute.  This routine uses
    //    Euler's method, which observes that:
    //
    //      P(0) = 1
    //      P(N) =   P(N-1)  + P(N-2)
    //             - P(N-5)  - P(N-7)
    //             + P(N-12) + P(N-15)
    //             - ...
    //
    //      where the numbers 1, 2, 5, 7, ... to be subtracted from N in the
    //      indices are the successive pentagonal numbers, (with both positive
    //      and negative indices) with the summation stopping when a negative
    //      index is reached.
    //
    //  First values:
    //
    //    N   P
    //
    //    0   1
    //    1   1
    //    2   2
    //    3   3
    //    4   5
    //    5   7
    //    6  11
    //    7  15
    //    8  22
    //    9  30
    //   10  42
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    28 May 2003
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Reference:
    //
    //    John Conway, Richard Guy,
    //    The Book of Numbers,
    //    Springer Verlag, 1996, page 95.
    //
    //  Parameters:
    //
    //    Input, int N, the index of the highest partition number desired.
    //
    //    Output, int P[N+1], the partition numbers.
    //
    {
        int i;

        p[0] = 1;

        for (i = 1; i <= n; i++)
        {
            p[i] = 0;

            int j   = 0;
            int sgn = 1;

            int pj;
            for (;;)
            {
                j += 1;
                pj = Pentagon.pentagon_num(j);

                if (i < pj)
                {
                    break;
                }

                p[i] += sgn * p[i - pj];
                sgn   = -sgn;
            }

            j   = 0;
            sgn = 1;

            for (;;)
            {
                j -= 1;
                pj = Pentagon.pentagon_num(j);

                if (i < pj)
                {
                    break;
                }

                p[i] += sgn * p[i - pj];
                sgn   = -sgn;
            }
        }
    }