Esempio n. 1
0
    private static void polyomino_embed_number_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    POLYOMINO_EMBED_NUMBER_TEST tests POLYOMINO_EMBED_NUMBER.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 May 2018
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int mp = 3;
        const int mr = 4;
        const int np = 2;
        const int nr = 4;

        int[] p =
        {
            0, 0, 1,
            1, 1, 1
        };
        int[] r =
        {
            0, 1, 1, 1,
            1, 1, 1, 0,
            1, 0, 1, 1,
            1, 1, 1, 1
        };

        Console.WriteLine("");
        Console.WriteLine("POLYOMINO_EMBED_NUMBER_TEST:");
        Console.WriteLine("  POLYOMINO_EMBED_NUMBER reports the number of ways a");
        Console.WriteLine("  fixed polyomino can be embedded in a region.");

        Polyomino.polyomino_print(mr, nr, r, "  The given region R:");

        Polyomino.polyomino_print(mp, np, p, "  The given polyomino P:");

        int number = Polyomino.polyomino_embed_number(mr, nr, r, mp, np, p);

        Console.WriteLine("");
        Console.WriteLine("  As a fixed polyomino, P can be embedded in R in " + number + " ways");
    }
Esempio n. 2
0
    private static void polyomino_condense_demo(int mp, int np, int[] p)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    polyomino_condense_demo demonstrates POLYOMINO_CONDENSE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    29 April 2018
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int MP, NP, the number of rows and columns in the representation
    //    of the polyomino P.
    //
    //    Input, int P[MP*NP], a matrix representing the polyomino.
    //
    //    Local, int MQ, NQ, the number of rows and columns in the representation
    //    of the condensed polyomino Q.
    //
    //    Local, int Q[MQ*NQ], a matrix representing the condensed polyomino.
    //
    {
        int mq = 0;
        int nq = 0;

        int[] q = null;

        string label = "  The initial (" + mp + "," + np + ") polynomino P:";

        Polyomino.polyomino_print(mp, np, p, label);

        Polyomino.polyomino_condense(mp, np, p, ref mq, ref nq, ref q);

        label = "  The condensed (" + mq + "," + nq + ") polynomino Q:";
        Polyomino.polyomino_print(mq, nq, q, label);
    }
Esempio n. 3
0
    private static void polyomino_transform_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    POLYOMINO_TRANSFORM_TEST tests POLYOMINO_TRANSFORM.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    28 April 2018
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Local parameters:
    //
    //    Local, int M, N, the number of rows and columns in the representation
    //    of the polyomino P.
    //
    //    Local, int P[M*N], a matrix of 0"s and 1"s representing the
    //    polyomino.  The matrix should be "tight", that is, there should be a
    //    1 in row 1, and in column 1, and in row M, and in column N.
    //
    {
        const int m  = 3;
        int       mq = 0;
        const int n  = 3;
        int       nq = 0;

        //
        //  P is given by columns, not rows.
        //
        int[] p =
        {
            0, 1, 0,
            1, 1, 1,
            1, 0, 0
        };
        int[] q = null;
        int   reflect;

        Console.WriteLine("");
        Console.WriteLine("POLYOMINO_TRANSFORM_TEST:");

        Console.WriteLine("  POLYOMINO_TRANSFORM can transform a polyomino.");
        Console.WriteLine("  Generate all 8 combinations of rotation and reflection");
        Console.WriteLine("  applied to a polyomino represented by a binary matrix.");

        Polyomino.polyomino_print(m, n, p, "  The given polyomino P:");

        for (reflect = 0; reflect <= 1; reflect++)
        {
            int rotate;
            for (rotate = 0; rotate <= 3; rotate++)
            {
                Polyomino.polyomino_transform(m, n, p, rotate, reflect, ref mq, ref nq, ref q);

                string label = "  P after " + reflect + " reflections and " + rotate + " rotations:";

                Polyomino.polyomino_print(mq, nq, q, label);
            }
        }

        Console.WriteLine("");
        Console.WriteLine("POLYOMINO_TRANSFORM_TEST:");
        Console.WriteLine("  Normal end of execution.");
    }
Esempio n. 4
0
    private static void polyomino_index_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    POLYOMINO_INDEX_TEST tests POLYOMINO_INDEX.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    30 April 2018
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int       i;
        const int m = 3;
        const int n = 4;

        //
        //  P is listed in column-major order;
        //
        int[] p =
        {
            1, 1, 0,
            0, 1, 1,
            1, 1, 1,
            1, 0, 0
        };

        Console.WriteLine("");
        Console.WriteLine("POLYOMINO_INDEX_TEST");

        Console.WriteLine("  POLYOMINO_INDEX assigns an index to each nonzero entry");
        Console.WriteLine("  of a polyomino.");

        Polyomino.polyomino_print(m, n, p, "  The polyomino P:");

        int[] pin = Polyomino.polyomino_index(m, n, p);

        Console.WriteLine("");
        Console.WriteLine("  PIN: Index vector for P:");
        Console.WriteLine("");
        for (i = 0; i < m; i++)
        {
            string cout = "";
            int    j;
            for (j = 0; j < n; j++)
            {
                cout += " " + pin[i + j * m];
            }

            Console.WriteLine(cout);
        }

        Console.WriteLine("");
        Console.WriteLine("POLYOMINO_INDEX_TEST");
        Console.WriteLine("  Normal end of execution.");
    }
Esempio n. 5
0
    private static void polyomino_embed_list_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    POLYOMINO_EMBED_LIST_TEST tests POLYOMINO_EMBED_LIST.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 May 2018
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int       k;
        const int mp = 3;
        const int mr = 4;
        const int np = 2;
        const int nr = 4;

        int[] p =
        {
            0, 0, 1,
            1, 1, 1
        };
        int[] q = new int[4 * 4];
        int[] r =
        {
            0, 1, 1, 1,
            1, 1, 1, 0,
            1, 0, 1, 1,
            1, 1, 1, 1
        };

        Console.WriteLine("");
        Console.WriteLine("POLYOMINO_EMBED_LIST_TEST:");
        Console.WriteLine("  POLYOMINO_EMBED_LIST lists the offsets used");
        Console.WriteLine("  to embed a fixed polyomino in a region.");

        Polyomino.polyomino_print(mr, nr, r, "  The given region R:");

        Polyomino.polyomino_print(mp, np, p, "  The given polyomino P:");
        //
        //  Get the number of embeddings.
        //
        int number = Polyomino.polyomino_embed_number(mr, nr, r, mp, np, p);

        Console.WriteLine("");
        Console.WriteLine("  As a fixed polyomino, P can be embedded in R in " + number + " ways");

        /*
         * Get the list of embeddings.
         */
        int[] list = Polyomino.polyomino_embed_list(mr, nr, r, mp, np, p, number);

        for (k = 0; k < number; k++)
        {
            int mk = list[k + 0 * number];
            int nk = list[k + 1 * number];

            int i;
            int j;
            for (j = 0; j < nr; j++)
            {
                for (i = 0; i < mr; i++)
                {
                    q[i + j * mr] = r[i + j * mr];
                }
            }

            for (j = 0; j < np; j++)
            {
                for (i = 0; i < mp; i++)
                {
                    q[i + mk + (j + nk) * mr] += p[i + j * mp];
                }
            }

            Console.WriteLine("");
            Console.WriteLine("  Embedding number " + k + ":");
            Console.WriteLine("");
            for (i = 0; i < mr; i++)
            {
                string cout = "";
                for (j = 0; j < nr; j++)
                {
                    cout += " " + q[i + j * mr];
                }

                Console.WriteLine(cout);
            }
        }
    }