Exemple #1
0
        bool WillBeActive(Tools.Coordination cube)
        {
            bool isActive            = IsActive(cube);
            int  numActiveNeighbours = NumActiveNeighbours(cube);

            if (isActive)
            {
                if (numActiveNeighbours == 2 || numActiveNeighbours == 3)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                if (numActiveNeighbours == 3)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Exemple #2
0
 DirectionsEx(int dim)
 {
     _actual = new Coordination(dim);
     for (int i = 0; i < _actual.Dim(); i++)
     {
         _actual[i] = -1;
     }
 }
Exemple #3
0
 bool IsInList(Tools.Coordination cube, List <Tools.Coordination> list)
 {
     foreach (var coord in list)
     {
         if (coord.Equals(cube))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #4
0
        int NumActiveNeighbours(Tools.Coordination cube)
        {
            int num = 0;

            foreach (var direction in _directions)
            {
                var coord = cube + direction;
                //Console.WriteLine("{0}, {1}, {2}", direction[0], direction[1], direction[2]);
                if (IsActive(coord))
                {
                    num++;
                }
            }
            return(num);
        }
Exemple #5
0
        void ReadInput(int dim)
        {
            _directions = Tools.DirectionsEx.Generate(dim);
            var lines = Tools.Common.ReadLines("input17.txt");

            _active = new List <Tools.Coordination>();
            for (int y = 0; y < lines.Length; y++)
            {
                for (int x = 0; x < lines[y].Length; x++)
                {
                    if (lines[y][x] == '#')
                    {
                        var coord = new Tools.Coordination(dim);
                        for (int i = 0; i < dim; i++)
                        {
                            coord[i] = 0;
                        }
                        coord[0] = x;
                        coord[1] = y;
                        _active.Add(coord);
                    }
                }
            }
        }
Exemple #6
0
 bool IsActive(Tools.Coordination cube)
 {
     return(IsInList(cube, _active));
 }