Ejemplo n.º 1
0
 public static string Day6(string input)
 {
     string output = "";
     if (noInput(input))
     {
         output = NOINPUT;
         return output;
     }
     string[] instructions = input.Split('\n');
     LightPoint[] lightGrid = new LightPoint[(int)10e5];
     int index = 0;
     for (int x = 0; x < 1000; x++)
     {
         for (int y = 0; y < 1000; y++)
         {
             lightGrid[index] = new LightPoint(false, new Point(x,y));
             index++;
         }
     }
     foreach (string instruction in instructions)
     {
         if (instruction.StartsWith("turn off"))
             lightGrid = turnOffRange(lightGrid, getRange(instruction));
         if (instruction.StartsWith("toggle"))
             lightGrid = toggleRange(lightGrid, getRange(instruction));
         if (instruction.StartsWith("turn on"))
             lightGrid = turnOnRange(lightGrid, getRange(instruction));
     }
     output += "The number of lights that are lit is: " + lightGrid.Count(x => x.isLit == true) + "\n The total brightness of the grid is: " + lightGrid.Sum(x => x.brightness);
     return output;
 }