Пример #1
0
 public PuzzleSolver(IEnumerable <string> input)
 {
     _enhancementDictionary = new Dictionary <PixelBlock, PixelBlock>();
     foreach (var line in input)
     {
         var splitResult   = Regex.Split(line, " => ");
         var rotatingBlock = new PixelBlock(splitResult[0]);
         var valueBlock    = new PixelBlock(splitResult[1]);
         _enhancementDictionary.Add(rotatingBlock, new PixelBlock(valueBlock));
         for (int i = 0; i < 3; i++)
         {
             var flipingBlock = rotatingBlock.FlipVertical;
             if (!_enhancementDictionary.ContainsKey(flipingBlock))
             {
                 _enhancementDictionary.Add(flipingBlock, valueBlock);
             }
             flipingBlock = rotatingBlock.FlipHorizontal;
             if (!_enhancementDictionary.ContainsKey(flipingBlock))
             {
                 _enhancementDictionary.Add(flipingBlock, valueBlock);
             }
             rotatingBlock = rotatingBlock.RotateRight;
             if (!_enhancementDictionary.ContainsKey(rotatingBlock))
             {
                 _enhancementDictionary.Add(rotatingBlock, valueBlock);
             }
         }
     }
 }
Пример #2
0
        public int SolveSecond()
        {
            var block = new PixelBlock(InitialBlock);

            for (int i = 0; i < 18; i++)
            {
                block = new PixelBlock(block.DivideBlocks().Select(pblock => _enhancementDictionary[pblock]));
            }
            return(block.ToString().Count(c => c == '#'));
        }
Пример #3
0
 public PixelBlock(PixelBlock pixelBlock)
 {
     _block = pixelBlock._block.Select(b => new BitArray(b)).ToList();
 }
Пример #4
0
 public bool Equals(PixelBlock other)
 {
     return(Equals(_block, other._block));
 }