Пример #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");
    }
Пример #2
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);
            }
        }
    }