示例#1
0
        /// <summary>Solve the 6x10 pentomino puzzle.</summary>
        public static void Main(string[] args)
        {
            int       width  = 6;
            int       height = 10;
            Pentomino model  = new Pentomino(width, height);
            IList     splits = model.GetSplits(2);

            for (IEnumerator splitItr = splits.GetEnumerator(); splitItr.HasNext();)
            {
                int[] choices = (int[])splitItr.Next();
                System.Console.Out.Write("split:");
                for (int i = 0; i < choices.Length; ++i)
                {
                    System.Console.Out.Write(" " + choices[i]);
                }
                System.Console.Out.WriteLine();
                System.Console.Out.WriteLine(model.Solve(choices) + " solutions found.");
            }
        }
        /// <summary>
        /// Create the input file with all of the possible combinations of the
        /// given depth.
        /// </summary>
        /// <param name="fs">the filesystem to write into</param>
        /// <param name="dir">the directory to write the input file into</param>
        /// <param name="pent">the puzzle</param>
        /// <param name="depth">the depth to explore when generating prefixes</param>
        /// <exception cref="System.IO.IOException"/>
        private static long CreateInputDirectory(FileSystem fs, Path dir, Pentomino pent,
                                                 int depth)
        {
            fs.Mkdirs(dir);
            IList <int[]> splits = pent.GetSplits(depth);
            Path          input  = new Path(dir, "part1");
            PrintWriter   file   = new PrintWriter(new OutputStreamWriter(new BufferedOutputStream
                                                                              (fs.Create(input), 64 * 1024), Charsets.Utf8));

            foreach (int[] prefix in splits)
            {
                for (int i = 0; i < prefix.Length; ++i)
                {
                    if (i != 0)
                    {
                        file.Write(',');
                    }
                    file.Write(prefix[i]);
                }
                file.Write('\n');
            }
            file.Close();
            return(fs.GetFileStatus(input).GetLen());
        }