Advent of code 2015 solutions https://adventofcode.com/2015/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6.py 906B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/python
  2. PART_TWO = True
  3. def turn_on(old):
  4. return old + 1 if PART_TWO else True
  5. def turn_off(old):
  6. return max(0, old - 1) if PART_TWO else False
  7. def toggle(old):
  8. return old + 2 if PART_TWO else not old
  9. with open('6.txt', 'r') as file:
  10. input = file.read()
  11. state = [[0 if PART_TWO else False for x in range(1000)] for y in range(1000)]
  12. for line in input.splitlines():
  13. if line.startswith('turn on'):
  14. action = turn_on
  15. line = line[8:]
  16. elif line.startswith('turn off'):
  17. action = turn_off
  18. line = line[9:]
  19. else:
  20. action = toggle
  21. line = line[7:]
  22. ((x1, y1), (x2, y2)) = [coord.split(',') for coord in line.split(' through ')]
  23. for x in range(int(x1), int(x2) + 1):
  24. for y in range(int(y1), int(y2) + 1):
  25. state[x][y] = action(state[x][y])
  26. count = sum([sum(col) for col in state])
  27. print(count)