Beispiel #1
0
        protected override string CalculatePart2(Input[] input)
        {
            //"Cheating" on run time by using using the result from Part1
            if (solvedMap == null)
            {
                CalculatePart1(input);
            }
            SquareImage <bool> image   = solvedMap.GetImage();          //Image image = solvedMap.Image;
            Pattern            pattern = Pattern.SeaMonster;
            SquareImage <bool> result  = new SquareImage <bool>(image.Size);

            foreach (Operation op in ValidOperations)
            {
                image.Transform  = op;
                result.Transform = op;
                foreach (Point p in image.GetIndices())
                {
                    pattern.Origin = p;
                    if (pattern.Match(image))
                    {
                        pattern.Or(result);
                    }
                }
            }

            //Now our result is any space marked as a wave in the original image and not a sea monster in our current results
            foreach (Point p in image.GetIndices())
            {
                result[p] = image[p] && !result[p];
            }

            return(result.GetData().Count(x => x == true).ToString());
        }
 public SquareImage(SquareImage <T> Copy) : this(Copy.Size)
 {
     for (int y = 0; y < Size; y++)
     {
         for (int x = 0; x < Size; x++)
         {
             this.data[x, y] = Copy.data[x, y];
         }
     }
 }