def test_turn_off(self): matrix = [[0 for x in range (5)] for x in range(5)] BrightGrid.processInstruction("turn on 1,1 through 3,3",matrix) BrightGrid.processInstruction("turn off 1,1 through 3,3",matrix) self.assertEqual(0, BrightGrid.countTotalBrightness(matrix)) BrightGrid.processInstruction("turn off 1,1 through 3,3",matrix) self.assertEqual(0, BrightGrid.countTotalBrightness(matrix))
def test_toggle(self): self.assertEqual(4, BrightGrid.applySwitch("toggle", 2))
def test_turn_on(self): self.assertEqual(1, BrightGrid.applySwitch("turn on", 0))
def test_turn_off(self): self.assertEqual(0, BrightGrid.applySwitch("turn off", 0))
# For a 1000 x 1000 grid of lights (which are initially off) # process a list of instructions that will # increase or decrease the brightness level of a rectangular range of lights # example: toggle 461,550 through 564,900 : set brightness level of range by 2 # note: decrease goes to a minimum value of 0, no negative values. # return the final count of lights that are on from brightGrid import BrightGrid matrix = [[0 for x in range (1000)] for x in range(1000)] f = open('input.txt','r') for line in f: BrightGrid.processInstruction(line,matrix) print(BrightGrid.countTotalBrightness(matrix))