Skip to content

Instantly share code, notes, and snippets.

@TimCastelijns
Created December 7, 2015 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TimCastelijns/ba7ba80789339b507942 to your computer and use it in GitHub Desktop.
Save TimCastelijns/ba7ba80789339b507942 to your computer and use it in GitHub Desktop.
grid = [[False for x in range(1000)] for y in range(1000)]
with open('day6.txt', 'r') as f:
for line in f.readlines():
instructions = line.split()
x1, y1 = (int(i) for i in instructions[-3].split(','))
x2, y2 = (int(i) for i in instructions[-1].split(','))
for x, row in enumerate(grid):
for y, col in enumerate(row):
if x1 <= x <= x2 and y1 <= y <= y2:
if instructions[0] == 'toggle':
# toggle
grid[x][y] = not grid[x][y]
elif instructions[1] == 'on':
# turn on
grid[x][y] = True
else:
# turn off
grid[x][y] = False
print sum(row.count(True) for row in grid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment