Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with open("input.txt","r") as file:
- cmnds = [ask[:-1] for ask in file.readlines()]
- lights = [[1 for i in range(1000)] for i in range(1000)]
- def on(cmnd):
- startx, starty = cmnd[0].split(',')
- endx, endy = cmnd[1].split(',')
- print(startx,starty)
- startx, starty = int(startx), int(starty)
- endx, endy = int(endx), int(endy)
- for i in range(startx,endx+1):
- if i == startx:
- for j in range(1000):
- if j >= starty:
- lights[i][j] = 0
- elif i == endx:
- for j in range(1000):
- if j <= endy:
- lights[i][j] = 0
- else:
- for j in range(1000):
- lights[i][j] = 0
- def off(cmnd):
- startx, starty = cmnd[0].split(',')
- endx, endy = cmnd[1].split(',')
- startx, starty = int(startx), int(starty)
- endx, endy = int(endx), int(endy)
- for i in range(startx,endx+1):
- if i == startx:
- for j in range(1000):
- if j >= starty:
- lights[i][j] = 1
- elif i == endx:
- for j in range(1000):
- if j <= endy:
- lights[i][j] = 1
- else:
- for j in range(1000):
- lights[i][j] = 1
- def toggle(cmnd):
- startx, starty = cmnd[0].split(',')
- endx, endy = cmnd[1].split(',')
- startx, starty = int(startx), int(starty)
- endx, endy = int(endx), int(endy)
- for i in range(startx,endx+1):
- if i == startx:
- for j in range(1000):
- if j >= starty:
- if lights[i][j] == 0:
- lights[i][j] = 1
- if lights[i][j] == 1:
- lights[i][j] = 0
- elif i == endx:
- for j in range(1000):
- if j <= endy:
- if lights[i][j] == 0:
- lights[i][j] = 1
- if lights[i][j] == 1:
- lights[i][j] = 0
- else:
- for j in range(1000):
- if lights[i][j] == 0:
- lights[i][j] = 1
- if lights[i][j] == 1:
- lights[i][j] = 0
- def search_on():
- lights_on = 0
- #Searches for lights that are equal to zero and counts them
- for i,row in enumerate(lights):
- for j, light in enumerate(row):
- if lights[i][j] == 0:
- lights_on += 1
- return lights_on
- for line in cmnds:
- if "turn on" in line:
- on(line.split()[2:3] + line.split()[4:])
- elif "turn off" in line:
- off(line.split()[2:3] + line.split()[4:])
- else:
- toggle(line.split()[1:2] + line.split()[3:])
- print(search_on())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement