Ejemplo n.º 1
0
        public virtual void SetBool(bool[,,,] v, BAsyncResult <Object> asyncResult)
        {
            BRequest_RemoteArrayTypes4dim_setBool req = new BRequest_RemoteArrayTypes4dim_setBool();

            req.vValue = v;
            transport.sendMethod(req, asyncResult);
        }
Ejemplo n.º 2
0
        private string FromTabNotes(ref bool[, , ,] aTab)
        {
            StringBuilder sb = new StringBuilder(81);

            for (int y = 0; y < 9; y++)
            {
                for (int x = 0; x < 9; x++)
                {
                    for (int ymin = 0; ymin < 9; ymin++)
                    {
                        for (int xmin = 0; xmin < 9; xmin++)
                        {
                            if (aTab[x, y, xmin, ymin])
                            {
                                sb.Append("1");
                            }
                            else
                            {
                                sb.Append("0");
                            }
                        }
                    }
                }
            }
            return(sb.ToString());
        }
Ejemplo n.º 3
0
 public Chunk(Vector3 chunkSize, Vector3 location, Island island)
 {
     this.mChunkSize     = chunkSize;
     this.mChunkLocation = location;
     this.mVisible       = new bool[16, 16, 16, 6];
     this.mIsland        = island;
 }
 List <Point>[] TableToPath(bool[,,,] isPrevAbove, int[] pos)
 {
     List <Point>[] halfPath = new List <Point> [2];
     for (int i = 0; i < 2; i++)
     {
         halfPath[i] = new List <Point>();
     }
     Point[] p = new Point[2];
     p[0] = new Point(pos[0], pos[1]);
     p[1] = new Point(pos[2], pos[0] + pos[1] - pos[2]);
     while (p[0].X >= 0 && p[0].Y >= 0)
     {
         for (int i = 0; i < 2; i++)
         {
             halfPath[i].Add(p[i]);
             if (isPrevAbove[pos[0], pos[1], pos[2], i])
             {
                 p[i] = new Point(p[i].X - 1, p[i].Y);
             }
             else
             {
                 p[i] = new Point(p[i].X, p[i].Y - 1);
             }
         }
         pos[0] = p[0].X;
         pos[1] = p[0].Y;
         pos[2] = p[1].X;
     }
     return(halfPath);
 }
Ejemplo n.º 5
0
            public void Load(int iters)
            {
                //var lines = System.IO.File.ReadAllLines(@"./day17/input_test.txt");
                var lines = System.IO.File.ReadAllLines(@"./day17/input.txt");

                dim = lines[0].Length + (iters + 1) * 2;
                if (dim % 2 == 0)
                {
                    dim++;
                }

                active = new bool[dim, dim, dim, dim];

                int middle = dim / 2;
                int m2     = dim / 3;

                for (int y = 0; y < lines.Length; y++)
                {
                    for (int x = 0; x < lines[y].Length; x++)
                    {
                        if (lines[y][x] == '#')
                        {
                            active[x + 1 + m2, y + 1 + m2, middle, middle] = true;
                        }
                    }
                }
            }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            var K = int.Parse(Console.ReadLine());

            S = Console.ReadLine();
            var L = S.Length;

            DP       = new int[L, L, L + 1, 2];
            Complete = new bool[L, L, L + 1, 2];
            for (int i = 0; i < L; i++)
            {
                for (int j = 0; j < L; j++)
                {
                    for (int k = 0; k < L; k++)
                    {
                        for (int l = 0; l < 2; l++)
                        {
                            DP[i, j, k, l]       = l == 1 ? int.MinValue : int.MaxValue;
                            Complete[i, j, k, l] = false;
                        }
                    }
                }
            }
            Console.WriteLine(rec(0, L - 1, K, 1) != int.MinValue ? $"OK\n{DP[0, L - 1, K, 1]}" : "NG");
        }
Ejemplo n.º 7
0
        public virtual void SetBool(bool[,,,] v)
        {
            BSyncResult <Object> asyncResult = new BSyncResult <Object>();

            SetBool(v, BAsyncResultHelper.ToDelegate <Object>(asyncResult));
            asyncResult.GetResult();
        }
Ejemplo n.º 8
0
    private void RunCycle(ref bool[,,,] space)
    {
        int size = space.GetLength(0);

        bool[,,,] nextspace = new bool[size, size, size, size];
        for (int x = 0; x < size; x++)
        {
            for (int y = 0; y < size; y++)
            {
                for (int z = 0; z < size; z++)
                {
                    for (int w = 0; w < size; w++)
                    {
                        int activeneighbors = ActiveNeighbors(space, x, y, z, w);
                        if (space[x, y, z, w])
                        {
                            nextspace[x, y, z, w] = activeneighbors == 2 || activeneighbors == 3;
                        }
                        else
                        {
                            nextspace[x, y, z, w] = activeneighbors == 3;
                        }
                    }
                }
            }
        }
        space = nextspace;
    }
Ejemplo n.º 9
0
        private static int CountOccupiedAdjacentSlots(bool[,,,] space, int slotX, int slotY, int slotZ, int slotF)
        {
            int count = 0;

            for (int f = slotF - 1; f <= slotF + 1; f++)
            {
                for (int z = slotZ - 1; z <= slotZ + 1; z++)
                {
                    for (int x = slotX - 1; x <= slotX + 1; x++)
                    {
                        for (int y = slotY - 1; y <= slotY + 1; y++)
                        {
                            if (
                                !(x == slotX && y == slotY && z == slotZ && f == slotF) &&
                                f >= 0 && f <= space.GetUpperBound(0) &&
                                z >= 0 && z <= space.GetUpperBound(1) &&
                                x >= 0 && x <= space.GetUpperBound(2) &&
                                y >= 0 && y <= space.GetUpperBound(3)
                                )
                            {
                                if (space[f, z, x, y] == true)
                                {
                                    count++;
                                }
                            }
                        }
                    }
                }
            }

            return(count);
        }
Ejemplo n.º 10
0
            private void IterateRules2(int iGen)
            {
                var nextGen = new bool[_finalDimXY, _finalDimXY, _finalDimWZ, _finalDimWZ];

                // Only live cubes are from CycleCount - iGen to CycleCount + _dimInput + iGen in x and y directions and
                // from CycleCount - iGen to CycleCount + iGen in the Z/W direction.

                for (var iRow = CycleCount - iGen; iRow < CycleCount + _dimInput + iGen; iRow++)
                {
                    for (var iCol = CycleCount - iGen; iCol < CycleCount + _dimInput + iGen; iCol++)
                    {
                        for (var iPlane1 = CycleCount - iGen; iPlane1 <= CycleCount + iGen; iPlane1++)
                        {
                            for (var iPlane2 = CycleCount - iGen; iPlane2 <= CycleCount + iGen; iPlane2++)
                            {
                                var  count = CountNeighbors2(iRow, iCol, iPlane1, iPlane2);
                                bool newVal;
                                var  oldVal = _universe4[iRow, iCol, iPlane1, iPlane2];
                                if (oldVal)
                                {
                                    newVal = (count == 2 || count == 3);
                                }
                                else
                                {
                                    newVal = count == 3;
                                }

                                nextGen[iRow, iCol, iPlane1, iPlane2] = newVal;
                            }
                        }
                    }
                }

                _universe4 = nextGen;
            }
Ejemplo n.º 11
0
        static int CountNeighbors4D(bool[,,,] quad, int w, int z, int y, int x)
        {
            int found  = 0;
            int neighb = 0;

            for (var l = Math.Max(0, w - 1); Math.Min(w + 1, quad.GetUpperBound(0)) >= l; ++l)
            {
                for (var k = Math.Max(0, z - 1); Math.Min(z + 1, quad.GetUpperBound(1)) >= k; ++k)
                {
                    for (var j = Math.Max(0, y - 1); Math.Min(y + 1, quad.GetUpperBound(2)) >= j; ++j)
                    {
                        for (var i = Math.Max(0, x - 1); Math.Min(x + 1, quad.GetUpperBound(3)) >= i; ++i)
                        {
                            if (w == l && z == k && y == j && x == i)
                            {
                                continue;
                            }
                            neighb++;
                            if (quad[l, k, j, i])
                            {
                                found++;
                            }
                        }
                    }
                }
            }

            return(found);
        }
Ejemplo n.º 12
0
        public void DoStep()
        {
            Console.WriteLine("DoStep");

            var newValues = new bool[
                _borders.XRange() + 1,
                _borders.YRange() + 1,
                _borders.ZRange() + 1,
                _borders.WRange() + 1];

            for (int ix = 0; ix <= _borders.XRange(); ix++)
            {
                for (int iy = 0; iy <= _borders.YRange(); iy++)
                {
                    for (int iz = 0; iz <= _borders.ZRange(); iz++)
                    {
                        for (int iw = 0; iw <= _borders.WRange(); iw++)
                        {
                            var activeNeighbors = AmountOfActiveNeighbors(ix + _borders.xMin, iy + _borders.yMin, iz + _borders.zMin, iw + _borders.wMin);
                            if (_values[ix, iy, iz, iw])
                            {
                                newValues[ix, iy, iz, iw] = (activeNeighbors == 2 || activeNeighbors == 3);
                            }
                            else
                            {
                                newValues[ix, iy, iz, iw] = (activeNeighbors == 3);
                            }
                        }
                    }
                }
            }
            _values = newValues;
            ExpandIfNeeded();
        }
Ejemplo n.º 13
0
        public HyperCube(int initSize)
        {
            var total = initSize * 2 + 1;

            _borders = new Borders(initSize);
            _values  = new bool[total, total, total, total];
        }
Ejemplo n.º 14
0
        static MaximumNumber DayWithMaximumPassengers(bool[,,,] passengers)
        {
            int[]         passengersPerDay      = new int[DAYS];
            int           counter               = 0;
            int           dayWithMostPassengers = 0;
            int           maxNumOfPass          = 0;
            MaximumNumber max = new MaximumNumber();

            for (int day = 0; day < DAYS; day++)
            {
                for (int train = 0; train < TRAINS_PER_DAY; train++)
                {
                    for (int car = 0; car < CARS; car++)
                    {
                        for (int seat = 0; seat < SEATS; seat++)
                        {
                            if (passengers[day, train, car, seat] == true)
                            {
                                counter++;
                            }
                        }
                    }
                }

                passengersPerDay[day] = counter;
                counter = 0;
                max     = FindMaxNumber(passengersPerDay);
                dayWithMostPassengers = max.number;
                maxNumOfPass          = max.maximumPassengers;
            }

            return(max);
        }
Ejemplo n.º 15
0
        static int CarWithMaximumPassengers(bool[,,,] passengers, int day, int train)
        {
            int[]         passengersPerCar      = new int[CARS];
            int           counter               = 0;
            int           carWithMostPassengers = 0;
            int           maxNumOfPass          = 0;
            MaximumNumber max = new MaximumNumber();

            for (int car = 0; car < CARS; car++)
            {
                for (int seat = 0; seat < SEATS; seat++)
                {
                    if (passengers[day, train, car, seat] == true)
                    {
                        counter++;
                    }
                }
                passengersPerCar[car] = counter;
                counter = 0;
                max     = FindMaxNumber(passengersPerCar);
                carWithMostPassengers = max.number;
                maxNumOfPass          = max.maximumPassengers;
            }

            Console.WriteLine("Maximum number of passengers is {0} in the car # {1}",
                              maxNumOfPass, carWithMostPassengers);
            return(carWithMostPassengers);
        }
Ejemplo n.º 16
0
        static int DailyTrainWithMaximumPassengers(bool[,,,] passengers, int day)
        {
            int[]         passengersPerTrain      = new int[TRAINS_PER_DAY];
            int           counter                 = 0;
            int           trainWithMostPassengers = 0;
            int           maxNumOfPass            = 0;
            MaximumNumber max = new MaximumNumber();

            for (int train = 0; train < TRAINS_PER_DAY; train++)
            {
                for (int car = 0; car < CARS; car++)
                {
                    for (int seat = 0; seat < SEATS; seat++)
                    {
                        if (passengers[day, train, car, seat] == true)
                        {
                            counter++;
                        }
                    }
                }
                passengersPerTrain[train] = counter;
                counter = 0;
                max     = FindMaxNumber(passengersPerTrain);
                trainWithMostPassengers = max.number;
                maxNumOfPass            = max.maximumPassengers;
            }

            Console.WriteLine("Maximum number of passengers is {0} in the train # {1}",
                              maxNumOfPass, trainWithMostPassengers);
            return(trainWithMostPassengers);
        }
Ejemplo n.º 17
0
        void Update4D()
        {
            var newGalaxy4D = new bool[size, size, size, size];

            for (var x = 0; x < galaxy4D.GetLength(0); x++)
            {
                for (var y = 0; y < galaxy4D.GetLength(1); y++)
                {
                    for (var z = 0; z < galaxy4D.GetLength(2); z++)
                    {
                        for (var w = 0; w < galaxy4D.GetLength(3); w++)
                        {
                            var neighbours = CountNeighbours4D(x, y, z, w);
                            if (galaxy4D[x, y, z, w])
                            {
                                newGalaxy4D[x, y, z, w] = neighbours is 2 or 3;
                            }
                            else
                            {
                                newGalaxy4D[x, y, z, w] = neighbours is 3;
                            }
                        }
                    }
                }
            }

            galaxy4D = newGalaxy4D;
        }
Ejemplo n.º 18
0
        private bool[,,,] IncreaseConfiguration4D(bool[,,,] configuration)
        {
            var xLength = configuration.GetLength(0);
            var yLength = configuration.GetLength(1);
            var zLength = configuration.GetLength(2);
            var wLength = configuration.GetLength(3);

            var increasedConfiguration = new bool[xLength + 2, yLength + 2, zLength + 2, wLength + 2];

            for (int x = 0; x < xLength; x++)
            {
                for (int y = 0; y < yLength; y++)
                {
                    for (int z = 0; z < zLength; z++)
                    {
                        for (int w = 0; w < wLength; w++)
                        {
                            if (configuration[x, y, z, w] == true)
                            {
                                increasedConfiguration[x + 1, y + 1, z + 1, w + 1] = true;
                            }
                        }
                    }
                }
            }

            return(increasedConfiguration);
        }
Ejemplo n.º 19
0
        private static int GetNeighborCount4D(bool[,,,] pd4d, int x, int y, int z, int a)
        {
            int count = 0;

            for (int l = a - 1; l < a + 2; l++)
            {
                for (int i = z - 1; i < z + 2; i++)
                {
                    for (int j = y - 1; j < y + 2; j++)
                    {
                        for (int k = x - 1; k < x + 2; k++)
                        {
                            if (i == z && j == y && k == x && l == a)
                            {
                                continue;
                            }
                            if (pd4d[k, j, i, l])
                            {
                                count++;
                            }
                        }
                    }
                }
            }
            return(count);
        }
Ejemplo n.º 20
0
        private int CountActiveCubes4D(bool[,,,] configuration)
        {
            var xLength = configuration.GetLength(0);
            var yLength = configuration.GetLength(1);
            var zLength = configuration.GetLength(2);
            var wLength = configuration.GetLength(3);

            var activeCubes = 0;

            for (int x = 0; x < xLength; x++)
            {
                for (int y = 0; y < yLength; y++)
                {
                    for (int z = 0; z < zLength; z++)
                    {
                        for (int w = 0; w < wLength; w++)
                        {
                            if (configuration[x, y, z, w] == true)
                            {
                                activeCubes++;
                            }
                        }
                    }
                }
            }

            return(activeCubes);
        }
Ejemplo n.º 21
0
        static void Problem2(string[] lines)
        {
            bool[,,,] quad = new bool[24, 24, 24, 24];
            int offsetXY = (quad.GetLength(0) / 2) - (lines.GetLength(0) / 2);
            int offsetZW = quad.GetLength(0) / 2;

            for (int y = 0; lines.Length > y; ++y)
            {
                for (int x = 0; lines[0].Length > x; ++x)
                {
                    quad[offsetZW, offsetZW, offsetXY + y, offsetXY + x] = '#' == lines[y][x];
                }
            }

            bool[,,,] next = (bool[, , , ])quad.Clone();
            for (int cycles = 0; 6 > cycles; ++cycles)
            {
                for (var w = 0; quad.GetLength(0) > w; ++w)
                {
                    for (var z = 0; quad.GetLength(1) > z; ++z)
                    {
                        for (var y = 0; quad.GetLength(2) > y; ++y)
                        {
                            for (var x = 0; quad.GetLength(3) > x; ++x)
                            {
                                int neighbors = CountNeighbors4D(quad, w, z, y, x);
                                next[w, z, y, x] = quad[w, z, y, x] ?
                                                   neighbors.IsWithin(2, 3) :
                                                   3 == neighbors;
                            }
                        }
                    }
                }

                var temp = quad;
                quad = next;
                next = temp;
            }


            int found = 0;

            for (var w = 0; quad.GetLength(0) > w; ++w)
            {
                for (var z = 0; quad.GetLength(1) > z; ++z)
                {
                    for (var y = 0; quad.GetLength(2) > y; ++y)
                    {
                        for (var x = 0; quad.GetLength(3) > x; ++x)
                        {
                            if (quad[w, z, y, x])
                            {
                                found++;
                            }
                        }
                    }
                }
            }
            Console.WriteLine("#2: " + found);
        }
Ejemplo n.º 22
0
        private bool[,,,] ProcessChanges4D(bool[,,,] changes, bool[,,,] configuration)
        {
            var xLength = configuration.GetLength(0);
            var yLength = configuration.GetLength(1);
            var zLength = configuration.GetLength(2);
            var wLength = configuration.GetLength(3);

            for (int x = 0; x < xLength; x++)
            {
                for (int y = 0; y < yLength; y++)
                {
                    for (int z = 0; z < zLength; z++)
                    {
                        for (int w = 0; w < wLength; w++)
                        {
                            if (changes[x, y, z, w] == true)
                            {
                                if (configuration[x, y, z, w] == true)
                                {
                                    configuration[x, y, z, w] = false;
                                }
                                else
                                {
                                    configuration[x, y, z, w] = true;
                                }
                            }
                        }
                    }
                }
            }

            return(configuration);
        }
Ejemplo n.º 23
0
    private int ActiveNeighbors(bool[,,,] space, int x, int y, int z, int w)
    {
        int size            = space.GetLength(0);
        int activeneighbors = 0;

        for (int dx = -1; dx <= 1; dx++)
        {
            for (int dy = -1; dy <= 1; dy++)
            {
                for (int dz = -1; dz <= 1; dz++)
                {
                    for (int dw = -1; dw <= 1; dw++)
                    {
                        int x2 = x + dx, y2 = y + dy, z2 = z + dz, w2 = w + dw;
                        if (x2 >= 0 && x2 < size && y2 >= 0 && y2 < size && z2 >= 0 && z2 < size && w2 >= 0 && w2 < size &&
                            !(x2 == x && y2 == y && z2 == z && w2 == w) && space[x2, y2, z2, w2])
                        {
                            activeneighbors++;
                        }
                    }
                }
            }
        }

        return(activeneighbors);
    }
Ejemplo n.º 24
0
        public override void write(Object obj1, BOutput bout1, long version)
        {
            BOutputBin bout = (BOutputBin)bout1;
            BBufferBin bbuf = bout.bbuf;

            bool[,,,] arr = (bool[, , , ])obj1;

            // lengths
            int n3 = arr.GetLength(0);
            int n2 = arr.GetLength(1);
            int n1 = arr.GetLength(2);
            int n0 = arr.GetLength(3);

            bbuf.putLength(n3);
            bbuf.putLength(n2);
            bbuf.putLength(n1);
            bbuf.putLength(n0);

            // write
            for (int i3 = 0; i3 < n3; i3++)
            {
                for (int i2 = 0; i2 < n2; i2++)
                {
                    for (int i1 = 0; i1 < n1; i1++)
                    {
                        for (int i0 = 0; i0 < n0; i0++)
                        {
                            bbuf.putBoolean(arr[i3, i2, i1, i0]);
                        }
                    }
                }
            }
        }
Ejemplo n.º 25
0
        private void Cycle4D()
        {
            var newPocket = CreatePocket4D(pocketSize);

            for (int w = 1; w < pocketSize - 1; w++)
            {
                for (int z = 1; z < pocketSize - 1; z++)
                {
                    for (int y = 1; y < pocketSize - 1; y++)
                    {
                        for (int x = 1; x < pocketSize - 1; x++)
                        {
                            var n = CountNeighbors4D(x, y, z, w);
                            if (pocket4D[x, y, z, w])
                            {
                                newPocket[x, y, z, w] = n == 2 || n == 3;
                            }
                            else
                            {
                                newPocket[x, y, z, w] = n == 3;
                            }
                        }
                    }
                }
            }
            pocket4D = newPocket;
        }
Ejemplo n.º 26
0
 public void ClearNotes()
 {
     _CheckedCell = new bool[9, 9, 9, 9];
     _FlagCell    = new bool[9, 9, 9, 9];
     DoFlagChanged();
     DoCheckChanged();
 }
Ejemplo n.º 27
0
        private void RunCycle()
        {
            var newState = new bool[
                _state.GetLength(0) + 2,
                _state.GetLength(1) + 2,
                _state.GetLength(2) + 2,
                _state.GetLength(3) + 2
                           ];

            for (var x = 0; x < newState.GetLength(0); x++)
            {
                for (var y = 0; y < newState.GetLength(1); y++)
                {
                    for (var z = 0; z < newState.GetLength(2); z++)
                    {
                        for (var w = 0; w < newState.GetLength(3); w++)
                        {
                            var neighbours = GetNeighbours(x, y, z, w);
                            if (IsActive(x, y, z, w))
                            {
                                newState[x, y, z, w] = (neighbours == 2 || neighbours == 3);
                            }
                            else
                            {
                                newState[x, y, z, w] = neighbours == 3;
                            }
                        }
                    }
                }
            }

            _state = newState;
        }
Ejemplo n.º 28
0
        private static bool[,,,] SimulateCycle(bool[,,,] cube)
        {
            var length  = cube.GetLength(1);
            var newCube = new bool[length, length, length, length];

            // Don't consider outer dimensions of cube.
            for (var x = 0; x < length; x++)
            {
                for (var y = 0; y < length; y++)
                {
                    for (var z = 0; z < length; z++)
                    {
                        for (var w = 0; w < length; w++)
                        {
                            var currentlyActive  = cube[x, y, z, w];
                            var activeNeighbours = ActiveNeighbours(cube, x, y, z, w);
                            if (currentlyActive)
                            {
                                newCube[x, y, z, w] = (activeNeighbours == 2 || activeNeighbours == 3);
                            }
                            else
                            {
                                newCube[x, y, z, w] = activeNeighbours == 3;
                            }
                        }
                    }
                }
            }

            return(newCube);
        }
Ejemplo n.º 29
0
        public string solve()
        {
            used = new bool[s.Length, 2 * 2 * 3 * 5 * 7 + 1, 2 * 3 * 5 * 7, 3];
            memo = new long[s.Length, 2 * 2 * 3 * 5 * 7 + 1, 2 * 3 * 5 * 7, 3];

            cnt = count(0, 0, 0, 0);
            return(string.Format("{0}", cnt));
        }
Ejemplo n.º 30
0
 public Field(int x, int z, int y, int w)
 {
     _x    = x;
     _z    = z;
     _y    = y;
     _w    = w;
     _data = new bool[x, z, y, w];
 }