Пример #1
0
        public FourCellPyramid(FourCellPyramid aParent, int aPypamidPyrLevel, bool aUpside)
        {
            ParentPyramid = aParent;
            PyramidLevel  = aPypamidPyrLevel;

            TopValue          = false;
            BottomLeftValue   = false;
            BottomUpsideValue = false;
            BottomRightValue  = false;
            Upside            = aUpside;
            TopLineLevel      = 0;
            BottomLineLevel   = 0;

            if (aPypamidPyrLevel > 1)
            {
                Top4CellPyramid          = new FourCellPyramid(this, aPypamidPyrLevel - 1, false);
                BottomLeft4CellPyramid   = new FourCellPyramid(this, aPypamidPyrLevel - 1, false);
                BottomUpside4CellPyramid = new FourCellPyramid(this, aPypamidPyrLevel - 1, true);
                BottomRight4CellPyramid  = new FourCellPyramid(this, aPypamidPyrLevel - 1, false);;
            }
            else
            {
                Top4CellPyramid          = null;
                BottomLeft4CellPyramid   = null;
                BottomUpside4CellPyramid = null;
                BottomRight4CellPyramid  = null;
            }
        }
Пример #2
0
        // Getting pattern of pyramid
        // true - values of all cells are "1"
        // false - values of all cells are "0"
        public bool Reduce(bool areducePossible)
        {
            bool res = false;

            // low level pyramids reducing is possible
            if (areducePossible)
            {
                // and level of pyramid is 1 (value containing pyramid),
                // return reduce value
                if (PyramidLevel == 1)
                {
                    res = TopValue;
                }
                // else, if level of pyramid is 2 (lowest group pyramid) and low level pyramids reducing is possible,
                // reduce it
                else if (PyramidLevel == 2)
                {
                    TopValue                 = Top4CellPyramid.Reduce(areducePossible);
                    BottomLeftValue          = BottomLeft4CellPyramid.Reduce(areducePossible);
                    BottomUpsideValue        = BottomUpside4CellPyramid.Reduce(areducePossible);
                    BottomRightValue         = BottomRight4CellPyramid.Reduce(areducePossible);
                    Top4CellPyramid          = null;
                    BottomLeft4CellPyramid   = null;
                    BottomUpside4CellPyramid = null;
                    BottomRight4CellPyramid  = null;
                    res = true;
                }
                else if (PyramidLevel > 2)
                {
                    Top4CellPyramid.Reduce(areducePossible);
                    BottomLeft4CellPyramid.Reduce(areducePossible);
                    BottomUpside4CellPyramid.Reduce(areducePossible);
                    BottomRight4CellPyramid.Reduce(areducePossible);
                    res = true;
                }
                PyramidLevel--;
            }
            return(res);
        }
Пример #3
0
        public PyramidClass(String aSource)
        {
            source = aSource;
            int len = source.Length;

            MaxLines    = 1;
            MaxPyrLevel = 0;
            while (len > 1)
            {
                len       = len / 4;
                MaxLines *= 2;
                MaxPyrLevel++;
            }
            MaxLines--;

            // Initializing top 4 cell pyramid
            TopPyramid = new FourCellPyramid(null, MaxPyrLevel, false);

            // defining line levels cells
            TopPyramid.DefLineLevels(0);

            // Filling pyramid from input string
            FillFromString(aSource);
        }
Пример #4
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Error: There are on input arguments.");
                Console.ReadLine();
                return;
            }

            String sSource = args[0];

            Console.WriteLine("tribit.exe {0}", sSource);

            // Input data checking. If input data is invalid, then exit
            if (!CheckSourceData(sSource))
            {
                Console.ReadLine();
                return;
            }

            // In case of 1 cell pyramid just print it and exit
            if (sSource.Length == 1)
            {
                Console.WriteLine("{0}", sSource);
                Console.ReadLine();
                return;
            }

            // Initialize entire pyramid
            PyramidClass Pyramid = new PyramidClass(sSource);

            // Print this pyramid
            Console.WriteLine("{0}", Pyramid.GetString());

            FourCellPyramid TopPyramid = Pyramid.TopPyramid;

            // Transition iteration process
            while (true)
            {
                // Make transition step
                TopPyramid.DoTransition();

                // Print pyramid on current step
                Console.WriteLine("{0}", Pyramid.GetString());

                // Check pyramid for posibility of reducing it
                if (TopPyramid.IsReducingPossible())
                {
                    // if reduce possible, do it
                    TopPyramid.Reduce(true);

                    // the changes
                    // after reducing of the pyramid we must redefine line levels for cells
                    TopPyramid.DefLineLevels(0);

                    // Print pyramid just after reducing
                    Console.WriteLine("{0}", Pyramid.GetString());
                }

                // if pattern of root pyramid is definded, then reduce this root pyramid and finish algorithm
                if ((TopPyramid.PyramidLevel <= 1) && TopPyramid.IsReducingPossible())
                {
                    int value = TopPyramid.TopValue ? 1 : 0;
                    Console.WriteLine("{0}", value);
                    break;
                }
            }

            Console.ReadLine();
            return;
        }