def test_turn_on(self): matrix = [[0 for x in range (5)] for x in range(5)] LightGrid.processInstruction("turn on 1,1 through 3,3",matrix) self.assertEqual(0, matrix[0][0]) self.assertEqual(0, matrix[0][1]) self.assertEqual(0, matrix[0][2]) self.assertEqual(0, matrix[0][3]) self.assertEqual(0, matrix[0][4]) self.assertEqual(0, matrix[1][0]) self.assertEqual(1, matrix[1][1]) self.assertEqual(1, matrix[1][2]) self.assertEqual(1, matrix[1][3]) self.assertEqual(0, matrix[1][4]) self.assertEqual(0, matrix[2][0]) self.assertEqual(1, matrix[2][1]) self.assertEqual(1, matrix[2][2]) self.assertEqual(1, matrix[2][3]) self.assertEqual(0, matrix[2][4]) self.assertEqual(0, matrix[3][0]) self.assertEqual(1, matrix[3][1]) self.assertEqual(1, matrix[3][2]) self.assertEqual(1, matrix[3][3]) self.assertEqual(0, matrix[3][4]) self.assertEqual(0, matrix[4][0]) self.assertEqual(0, matrix[4][1]) self.assertEqual(0, matrix[4][2]) self.assertEqual(0, matrix[4][3]) self.assertEqual(0, matrix[4][4])
def test_turn_on(self): matrix = [[0 for x in range (5)] for x in range(5)] LightGrid.processInstruction("turn on 1,1 through 3,3",matrix) self.assertEqual(9, LightGrid.countOnLights(matrix))
# For a 1000 x 1000 grid of lights (which are initially off) # process a list of instructions that will # turn on, turn off or toggle a rectangular range of lights # example: toggle 461,550 through 564,900 # return the final count of lights that are on from lightGrid import LightGrid matrix = [[0 for x in range (1000)] for x in range(1000)] f = open('input.txt','r') for line in f: LightGrid.processInstruction(line,matrix) print(LightGrid.countOnLights(matrix))