コード例 #1
0
        public virtual void SetChar(char[,,,] v)
        {
            BSyncResult <Object> asyncResult = new BSyncResult <Object>();

            SetChar(v, BAsyncResultHelper.ToDelegate <Object>(asyncResult));
            asyncResult.GetResult();
        }
コード例 #2
0
        public virtual void SetChar(char[,,,] v, BAsyncResult <Object> asyncResult)
        {
            BRequest_RemoteArrayTypes4dim_setChar req = new BRequest_RemoteArrayTypes4dim_setChar();

            req.vValue = v;
            transport.sendMethod(req, asyncResult);
        }
コード例 #3
0
        public override void write(Object obj1, BOutput bout1, long version)
        {
            BOutputBin bout = (BOutputBin)bout1;
            BBufferBin bbuf = bout.bbuf;

            char[,,,] arr = (char[, , , ])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.putChar(arr[i3, i2, i1, i0]);
                        }
                    }
                }
            }
        }
コード例 #4
0
        private void NextCycle(int cycle, bool part2 = false)
        {
            var limit  = cycle + 11;
            var wLimit = part2 ? limit + 3 : 0;

            for (int w = -wLimit; w <= wLimit; w++)
            {
                for (int z = -limit; z < limit + 3; z++)
                {
                    for (int y = -limit; y < limit + 3; y++)
                    {
                        for (int x = -limit; x < limit + 3; x++)
                        {
                            int numberOfNeighbours = countNeighbours(y, x, z, w);
                            if (IsPositionActive(y, x, z, w) == 1 && (numberOfNeighbours == 2 || numberOfNeighbours == 3))
                            {
                                nextState[50 + y, 50 + x, 50 + z, 50 + w] = '#';
                            }
                            else if (IsPositionActive(y, x, z, w) == 0 && numberOfNeighbours == 3)
                            {
                                nextState[50 + y, 50 + x, 50 + z, 50 + w] = '#';
                            }
                            else
                            {
                                nextState[50 + y, 50 + x, 50 + z, 50 + w] = '.';
                            }
                        }
                    }
                }
            }
            currentState = (char[, , , ])nextState.Clone();
        }
コード例 #5
0
ファイル: Day17.cs プロジェクト: Shooterek/AdventOfCode2020
    private void ChangeState4(char[,,,] space, char[,,,] temp, int spaceSize, int x, int y, int z, int k)
    {
        var activeNeighboursCounter = 0;

        for (int i = -1; i < 2; i++)
        {
            for (int j = -1; j < 2; j++)
            {
                for (int a = -1; a < 2; a++)
                {
                    for (int b = -1; b < 2; b++)
                    {
                        if (i != 0 || j != 0 || a != 0 || b != 0)
                        {
                            activeNeighboursCounter += CheckNeighbour4(temp, spaceSize, x + i, y + j, a + z, k + b);
                        }
                    }
                }
            }
        }

        if (temp[x, y, z, k] == '#')
        {
            space[x, y, z, k] = activeNeighboursCounter == 2 || activeNeighboursCounter == 3 ? '#' : '.';
        }
        else
        {
            space[x, y, z, k] = activeNeighboursCounter == 3 ? '#' : '.';
        }
    }
コード例 #6
0
        public void SetNewState()
        {
            char[,,,] newState = CreateNewBoard(BoardState.GetLength(0), BoardState.GetLength(1), BoardState.GetLength(2), BoardState.GetLength(3), OFF);
            newState           = CopyBoard(BoardState, newState);
            for (int w = 0; w < BoardState.GetLength(0); w++)
            {
                for (int z = 0; z < BoardState.GetLength(1); z++)
                {
                    for (int y = 0; y < BoardState.GetLength(2); y++)
                    {
                        for (int x = 0; x < BoardState.GetLength(3); x++)
                        {
                            int activeNeighbors = GetActiveNeighborCount(w, z, y, x);
                            if (BoardState[w, z, y, x] == ON && activeNeighbors >= 2 && activeNeighbors <= 3)
                            {
                                newState[w, z, y, x] = ON;
                            }
                            else
                            {
                                newState[w, z, y, x] = OFF;
                            }

                            if (BoardState[w, z, y, x] == OFF && activeNeighbors == 3)
                            {
                                newState[w, z, y, x] = ON;
                            }
                        }
                    }
                }
            }
            BoardState = CopyBoard(newState, BoardState);
        }
コード例 #7
0
ファイル: Day17.cs プロジェクト: glhillman/AdventOfCode2020
        private void Cycle2(char[,,,] src, char[,,,] dst)
        {
            ClearCube4(dst);

            for (int x = _startIndex; x < _startIndex + _xySize; x++)
            {
                for (int y = _startIndex; y < _startIndex + _xySize; y++)
                {
                    for (int z = _startIndex; z < _startIndex + _zwSize; z++)
                    {
                        for (int w = _startIndex; w < _startIndex + _zwSize; w++)
                        {
                            int nActiveNeighbors = CountActiveNeighbors4(src, x, y, z, w);

                            if (src[x, y, z, w] == '#')
                            {
                                dst[x, y, z, w] = nActiveNeighbors == 2 || nActiveNeighbors == 3 ? '#' : '.';
                            }
                            else
                            {
                                dst[x, y, z, w] = nActiveNeighbors == 3 ? '#' : '.';
                            }
                        }
                    }
                }
            }

            _startIndex--;
            _xySize += 2;
            _zwSize += 2;
        }
コード例 #8
0
        public void GrowBoard()
        {
            int newW = BoardState.GetLength(0);
            int newZ = BoardState.GetLength(1);
            int newY = BoardState.GetLength(2);
            int newX = BoardState.GetLength(3);

            (bool w, bool z, bool y, bool x) = ShouldGrowBoard();
            if (w || z || y || x)
            {
                if (w)
                {
                    newW += 2;
                }
                if (z)
                {
                    newZ += 2;
                }
                if (y)
                {
                    newY += 2;
                }
                if (x)
                {
                    newX += 2;
                }

                char[,,,] newBoard = CreateNewBoard(newW, newZ, newY, newX, OFF);
                BoardState         = CopyBoard(BoardState, newBoard);
            }
        }
コード例 #9
0
        static char[,,,] TransformCube(char[,,,] curCube)
        {
            int cubeLength = curCube.GetLength(0);

            char[,,,] newCube = new char[cubeLength, cubeLength, cubeLength, cubeLength];

            for (int x = 0; x < cubeLength; x++)
            {
                for (int y = 0; y < cubeLength; y++)
                {
                    for (int z = 0; z < cubeLength; z++)
                    {
                        for (int w = 0; w < cubeLength; w++)
                        {
                            int numActiveNeighbours = CountActiveNeighbours(curCube, x, y, z, w);

                            if (curCube[x, y, z, w] == '#' && (numActiveNeighbours == 2 || numActiveNeighbours == 3))
                            {
                                newCube[x, y, z, w] = '#';
                            }
                            else if (curCube[x, y, z, w] == '.' && numActiveNeighbours == 3)
                            {
                                newCube[x, y, z, w] = '#';
                            }
                            else
                            {
                                newCube[x, y, z, w] = '.';
                            }
                        }
                    }
                }
            }

            return(newCube);
        }
コード例 #10
0
ファイル: CubeUtils.cs プロジェクト: jdraines/aoc2020
        public static int CountActiveNeighbors(char[,,,] map, int x, int y, int z, int w)
        {
            int count = 0;

            for (int i = x - 1; i < x + 2; i++)
            {
                for (int j = y - 1; j < y + 2; j++)
                {
                    for (int k = z - 1; k < z + 2; k++)
                    {
                        for (int n = w - 1; n < w + 2; n++)
                        {
                            if (i == x && j == y && k == z && n == w)
                            {
                            }
                            else if (
                                (i >= 0 && j >= 0 && k >= 0 && n >= 0) &&
                                (i < map.GetLength(0) && j < map.GetLength(1) && k < map.GetLength(2) && n < map.GetLength(3))
                                )
                            {
                                if (map[i, j, k, n] == '#')
                                {
                                    count++;
                                }
                            }
                        }
                    }
                }
            }
            return(count);
        }
コード例 #11
0
        private static void readInputCuboid()
        {
            string lineReader;

            lineReader = Console.ReadLine();
            string[] dimentions = lineReader.Split(' ');
            width  = int.Parse(dimentions[0]);
            height = int.Parse(dimentions[1]);
            depth  = int.Parse(dimentions[2]);
            cuboid = new char[width, height, depth, 2];

            for (int h = 0; h < height; h++)
            {
                lineReader = Console.ReadLine();
                string[] widthColors = lineReader.Split(' ');
                for (int d = 0; d < depth; d++)
                {
                    char[] inputData = widthColors[d].ToCharArray();
                    for (int w = 0; w < width; w++)
                    {
                        //Console.WriteLine("D == {0}, W == {1}",d,w);
                        cuboid[w, h, d, 0] = inputData[w];
                    }
                }
            }
        }
コード例 #12
0
        private static int CountAdjacentFields(int x, int y, int z, int t, char[,,,] matrix, int maxWidth, int maxHeight, int maxDepth, int maxTime)
        {
            int count = 0;

            for (int i = x - 1; i >= 0 && i < maxWidth && i <= x + 1; i++)
            {
                for (int j = y - 1; j >= 0 && j < maxHeight && j <= y + 1; j++)
                {
                    for (int k = z - 1; k >= 0 && k < maxDepth && k <= z + 1; k++)
                    {
                        for (int l = t - 1; l >= 0 && l < maxTime && l <= t + 1; l++)
                        {
                            if (!(i == x && j == y && k == z && l == t))
                            {
                                if (matrix[i, j, k, l] == ACTIVE)
                                {
                                    count++;
                                }
                            }
                        }
                    }
                }
            }
            return(count);
        }
コード例 #13
0
ファイル: CubeUtils.cs プロジェクト: jdraines/aoc2020
        public static char[,,,] EnlargeMap(char[,,,] map)
        {
            char[,,,] enlarged = new char[map.GetLength(0) + 2, map.GetLength(1) + 2, map.GetLength(2) + 2, map.GetLength(3) + 2];

            for (int i = 0; i < enlarged.GetLength(0); i++)
            {
                for (int j = 0; j < enlarged.GetLength(1); j++)
                {
                    for (int k = 0; k < enlarged.GetLength(2); k++)
                    {
                        for (int n = 0; n < enlarged.GetLength(3); n++)
                        {
                            enlarged[i, j, k, n] = '.';
                        }
                    }
                }
            }

            for (int i = 0; i < map.GetLength(0); i++)
            {
                for (int j = 0; j < map.GetLength(1); j++)
                {
                    for (int k = 0; k < map.GetLength(2); k++)
                    {
                        for (int n = 0; n < map.GetLength(3); n++)
                        {
                            enlarged[i + 1, j + 1, k + 1, n + 1] = map[i, j, k, n];
                        }
                    }
                }
            }

            return(enlarged);
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: mjsmith11/AOC
        static int checkNeighbors4(char[,,,] space, int w, int x, int y, int z, int size)
        {
            int num = 0;

            for (int checkw = -1; checkw <= 1; checkw++)
            {
                for (int checkx = -1; checkx <= 1; checkx++)
                {
                    for (int checky = -1; checky <= 1; checky++)
                    {
                        for (int checkz = -1; checkz <= 1; checkz++)
                        {
                            if (checkw != 0 || checkx != 0 || checky != 0 || checkz != 0)
                            {
                                if (checkCube4(space, w + checkw, x + checkx, y + checky, z + checkz, size))
                                {
                                    num++;
                                }
                            }
                        }
                    }
                }
            }
            return(num);
        }
コード例 #15
0
        public void Solve()
        {
            long   part1   = 0;
            long   part2   = 0;
            string allText = File.ReadAllText("Input\\2020\\day17.txt");
            var    lines   = allText.Split("\r\n").ToList();
            var    offset  = 50;

            for (int row = 0; row < lines.Count; row++)
            {
                for (int col = 0; col < lines[row].Length; col++)
                {
                    currentState[offset + row, offset + col, offset, offset]  = lines[row][col];
                    originalState[offset + row, offset + col, offset, offset] = lines[row][col];
                }
            }
            for (int i = 0; i < 6; i++)
            {
                NextCycle(i);
            }
            part1 = CountActive();

            currentState = (char[, , , ])originalState.Clone();
            for (int i = 0; i < 6; i++)
            {
                NextCycle(i, true);
            }
            part2 = CountActive();

            WriteResult(17, part1, part2, result.gold);
        }
コード例 #16
0
ファイル: Day17.cs プロジェクト: sevans00/AdventOfCode2020
            private int GetAdjacentCellActiveCount(char[,,,] map, int centerX, int centerY, int centerZ, int centerT)
            {
                int sum = 0;

                for (int x = centerX - 1; x <= centerX + 1; x++)
                {
                    for (int y = centerY - 1; y <= centerY + 1; y++)
                    {
                        for (int z = centerZ - 1; z <= centerZ + 1; z++)
                        {
                            for (int w = centerT - 1; w <= centerT + 1; w++)
                            {
                                if (
                                    x == centerX &&
                                    y == centerY &&
                                    z == centerZ &&
                                    w == centerT
                                    )
                                {
                                    continue;
                                }
                                if (IsInMap(x, y, z, w))
                                {
                                    if (map[x, y, z, w] == '#')
                                    {
                                        sum++;
                                    }
                                }
                            }
                        }
                    }
                }
                return(sum);
            }
コード例 #17
0
ファイル: Day17.cs プロジェクト: sevans00/AdventOfCode2020
            private char GetStepCellAt(char[,,,] map, int x, int y, int z, int w)
            {
                /*
                 * If a cube is active and exactly 2 or 3 of its neighbors are also active, the cube remains active. Otherwise, the cube becomes inactive.
                 * If a cube is inactive but exactly 3 of its neighbors are active, the cube becomes active. Otherwise, the cube remains inactive.
                 */
                var currentState = map[x, y, z, w];

                if (currentState == '#')
                {
                    //Occupied!
                    var numActive = GetAdjacentCellActiveCount(map, x, y, z, w);
                    if (numActive == 2 || numActive == 3)
                    {
                        return('#');
                    }
                    return('.');
                }
                if (currentState == '.')
                {
                    var numActive = GetAdjacentCellActiveCount(map, x, y, z, w);
                    if (numActive == 3)
                    {
                        return('#');
                    }
                    return('.');
                }
                return(currentState);
            }
コード例 #18
0
ファイル: Day17.cs プロジェクト: sevans00/AdventOfCode2020
            public BatMap2(string[] inputStrings)
            {
                map = new char[width, depth, height, thlabber];
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        for (int z = 0; z < depth; z++)
                        {
                            for (int w = 0; w < thlabber; w++)
                            {
                                map[x, y, z, w] = '.';
                            }
                        }
                    }
                }
                int halfW  = dimension / 2 - inputStrings[0].Length / 2;
                int halfH  = dimension / 2 - inputStrings[0].Length / 2;
                int halfD  = dimension / 2 - inputStrings[0].Length / 2;
                int halfTh = dimension / 2 - inputStrings[0].Length / 2;

                for (int y = 0; y < inputStrings.Length; y++)
                {
                    for (int x = 0; x < inputStrings[0].Length; x++)
                    {
                        map[x + halfW, y + halfH, halfD, halfTh] = inputStrings[x][y];
                    }
                }
            }
コード例 #19
0
        private static void ModifyNextMatrix(int x, int y, int z, int t, char[,,,] matrix, char[,,,] nextMatrix, int maxWidth, int maxHeight, int maxDepth, int maxTime)
        {
            int numberOfSurroundingActives = CountAdjacentFields(x, y, z, t, matrix, maxWidth, maxHeight, maxDepth, maxTime);

            //Console.WriteLine(String.Format("{0} {1} {2} ==> {3} neighbours", x, y, z, numberOfSurroundingActives));

            // Implement rules
            // Rule 1: If a cube is active and exactly 2 or 3 of its neighbors are also active, the cube remains active. Otherwise, the cube becomes inactive.
            if (matrix[x, y, z, t] == ACTIVE)
            {
                if (numberOfSurroundingActives == 2 || numberOfSurroundingActives == 3)
                {
                    nextMatrix[x, y, z, t] = ACTIVE;
                }
                else
                {
                    nextMatrix[x, y, z, t] = INACTIVE;
                }
            }
            // Rule 2: If a cube is inactive but exactly 3 of its neighbors are active, the cube becomes active. Otherwise, the cube remains inactive.
            else if (matrix[x, y, z, t] == INACTIVE)
            {
                if (numberOfSurroundingActives == 3)
                {
                    nextMatrix[x, y, z, t] = ACTIVE;
                }
                else
                {
                    nextMatrix[x, y, z, t] = INACTIVE;
                }
            }
        }
コード例 #20
0
        // checkpoint byps.gen.cs.GenRemoteStub:133
        public async Task SetCharAsync(char[,,,] v)
        {
            BRequest_RemoteArrayTypes4dim_setChar req = new BRequest_RemoteArrayTypes4dim_setChar();

            req.vValue = v;
            Task <Object> task = Task <Object> .Factory.FromAsync(transport.BeginSend <Object>, transport.EndSend <Object>, req, null);

            await task;
        }
コード例 #21
0
ファイル: Day17Puzzle.cs プロジェクト: jdraines/aoc2020
        public void SolvePart2()
        {
            char[,,,] map = CubeUtils.GetInputMap4D();

            for (int i = 0; i < 6; i++)
            {
                map = CubeUtils.UpdateMap(map);
            }
            Console.WriteLine($"Number of active cubes: {CubeUtils.CountActive(map)}");
        }
コード例 #22
0
 public BaseDisplayer(char c, char col, char back) //tests
 {
     this.img = new char[1, 1, 3, 4];
     for (int i = 0; i < 4; i++)
     {
         this.img[0, 0, 0, i] = 'x';
         this.img[0, 0, 1, i] = col;
         this.img[0, 0, 2, i] = back;
     }
 }
コード例 #23
0
        private static char GetNew2(char[,,,] grid, int w, int x, int y, int z)
        {
            int  count = 0;
            char th    = '.';

            if (!(w < 0 || x < 0 || y < 0 || z < 0 || w >= grid.GetLength(0) || x >= grid.GetLength(1) || y >= grid.GetLength(2) || z >= grid.GetLength(3)))
            {
                th = grid[w, x, y, z];
            }
            for (int ow = -1; ow <= 1; ow++)
            {
                for (int ox = -1; ox <= 1; ox++)
                {
                    for (int oy = -1; oy <= 1; oy++)
                    {
                        for (int oz = -1; oz <= 1; oz++)
                        {
                            if (ow + w < 0 || ow + w >= grid.GetLength(0))
                            {
                                continue;
                            }
                            if (ox + x < 0 || ox + x >= grid.GetLength(1))
                            {
                                continue;
                            }
                            if (oy + y < 0 || oy + y >= grid.GetLength(2))
                            {
                                continue;
                            }
                            if (oz + z < 0 || oz + z >= grid.GetLength(3))
                            {
                                continue;
                            }
                            if (ow == 0 && ox == 0 && oy == 0 && oz == 0)
                            {
                                continue;
                            }
                            if (grid[ow + w, ox + x, oy + y, oz + z] == '#')
                            {
                                count++;
                            }
                        }
                    }
                }
            }
            if (th == '.' && count == 3)
            {
                return('#');
            }
            if (th == '#' && (count == 2 || count == 3))
            {
                return('#');
            }
            return('.');
        }
コード例 #24
0
        public HyperCube(string board)
        {
            int boardSize = (int)Math.Pow(board.Length, 1 / 2.0);

            BoardState = new char[1, 1, boardSize, boardSize];
            for (int i = 0; i < board.Length; i++)
            {
                int currY = i / boardSize;
                int currX = i % boardSize;
                BoardState[0, 0, currY, currX] = board[i];
            }
        }
コード例 #25
0
ファイル: ArrayTypes4dim.cs プロジェクト: teberhardt/byps
 public ArrayTypes4dim(bool[,,,] @boolean4, byte[,,,] @byte4, char[,,,] @char4, short[,,,] @short4, int[,,,] @int4, long[,,,] @long4, float[,,,] @float4, double[,,,] @double4, String[,,,] @string4, byps.test.api.prim.PrimitiveTypes[,,,] @primitiveTypes4)
 {
     this.boolean4Value        = @boolean4;
     this.byte4Value           = @byte4;
     this.char4Value           = @char4;
     this.short4Value          = @short4;
     this.int4Value            = @int4;
     this.long4Value           = @long4;
     this.float4Value          = @float4;
     this.double4Value         = @double4;
     this.string4Value         = @string4;
     this.primitiveTypes4Value = @primitiveTypes4;
 }
コード例 #26
0
ファイル: Day17.cs プロジェクト: sebrighte/Advent-of-Code
        public char[,,,] ApplyCycle(int recurse)
        {
            int CRPRes = 0;

            char[,,,] tmpCube = this.CopyCube();
            for (int r = 0; r < recurse; r++)
            {
                //Console.WriteLine("Cycle " + (r + 1) + " of " + recurse);
                //DrawTextProgressBar(r, recurse-1);
                tmpCube = this.CopyCube();
                for (int z = 0; z < size; z++)
                {
                    for (int x = 0; x < size; x++)
                    {
                        for (int y = 0; y < size; y++)
                        {
                            for (int w = 0; w < size; w++)
                            {
                                if (cube[x, y, z, w] == '#' || cube[x, y, z, w] == '.')
                                {
                                    CRPRes = CountRoundPoint(x, y, z, w);
                                }

                                if (cube[x, y, z, w] == '#')
                                {
                                    if ((CRPRes == 2) || (CRPRes == 3))
                                    {
                                    }
                                    else
                                    {
                                        tmpCube[x, y, z, w] = '.';
                                    }
                                }
                                if (cube[x, y, z, w] == '.')
                                {
                                    if (CRPRes == 3)
                                    {
                                        tmpCube[x, y, z, w] = '#';
                                    }
                                }
                            }
                        }
                    }
                }
                cube = tmpCube;
            }
            return(tmpCube);
        }
コード例 #27
0
ファイル: Day17.cs プロジェクト: glhillman/AdventOfCode2020
 private void ClearCube4(char[,,,] cube)
 {
     for (int x = 0; x < MAX; x++)
     {
         for (int y = 0; y < MAX; y++)
         {
             for (int z = 0; z < MAX; z++)
             {
                 for (int w = 0; w < MAX; w++)
                 {
                     cube[x, y, z, w] = '.';
                 }
             }
         }
     }
 }
コード例 #28
0
ファイル: Day17.cs プロジェクト: Shooterek/AdventOfCode2020
 private void RunACycle4(char[,,,] space, char[,,,] temp, int spaceSize)
 {
     for (int x = 0; x < spaceSize; x++)
     {
         for (int y = 0; y < spaceSize; y++)
         {
             for (int z = 0; z < spaceSize; z++)
             {
                 for (int k = 0; k < spaceSize; k++)
                 {
                     ChangeState4(space, temp, spaceSize, x, y, z, k);
                 }
             }
         }
     }
 }
コード例 #29
0
ファイル: Day17.cs プロジェクト: Shooterek/AdventOfCode2020
 private void Copy4DCharrArray(char[,,,] source, char[,,,] dest, int spaceSize)
 {
     for (int i = 0; i < spaceSize; i++)
     {
         for (int j = 0; j < spaceSize; j++)
         {
             for (int a = 0; a < spaceSize; a++)
             {
                 for (int b = 0; b < spaceSize; b++)
                 {
                     dest[i, j, a, b] = source[i, j, a, b];
                 }
             }
         }
     }
 }
コード例 #30
0
        static void Main()
        {
            int numCycles = 6;

            char[,,,] curCube = InitCube(numCycles);

            for (int i = 0; i < numCycles; i++)
            {
                char[,,,] newCube = TransformCube(curCube);
                curCube           = newCube;
            }

            Console.WriteLine($"The number of active cubes is {CountActiveCubes(curCube)}");

            // PrintLayout(curCube);
        }