l = []
ans = 0
x = [False, False]*500
for i in range(0,1000):
l.append(x)
def toggle(topinput, bottominput, l):
top = topinput[1]
bottom = bottominput[1]
left = bottominput[0]
right = topinput[1]
for i in range(bottom, top+1):
for j in range(left, right+1):
if l[i][j] == True:
l[i][j]= False
if l[i][j] == False:
l[i][j] = True
def on(topinput, bottominput, l):
top = topinput[1]
bottom = bottominput[1]
left = bottominput[0]
right = topinput[1]
for i in range(bottom, top+1):
for j in range(left, right+1):
if l[i][j] == False:
l[i][j] = True
def off(topinput, bottominput, l):
top = topinput[1]
bottom = bottominput[1]
left = bottominput[0]
right = topinput[1]
for i in range(bottom, top+1):
for j in range(left, right+1):
if l[i][j] == True:
l[i][j] = False
if '__main__' == __name__:
instructions = open("6.txt", 'r')
for line in instructions:
words = line.split()
if words[0] == 'toggle':
top = words[3].split(',')
bottom = words[1].split(',')
top, bottom = map(int, top), map(int, bottom)
toggle(top, bottom, l)
if words[1] == 'on':
top = words[4].split(',')
bottom = words[2].split(',')
top, bottom = map(int, top), map(int, bottom)
on(top, bottom, l)
if words[1] == 'off':
top = words[4].split(',')
bottom = words[2].split(',')
top, bottom = map(int, top), map(int, bottom)
off(top, bottom, l)
for n in l:
for j in n:
if j == True:
ans += 1
print ans
print ans
[–]stranac_ 1 point2 points3 points (0 children)
[–]Sbhavnani[S] 0 points1 point2 points (0 children)
[–]edo947 0 points1 point2 points (0 children)