Advent of Code 2016 solutions https://adventofcode.com/2016/
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.

08.py 677B

123456789101112131415161718192021
  1. #!/usr/bin/python3
  2. import re
  3. import numpy as np
  4. with open('data/08.txt', 'r') as file:
  5. lines = list(map(str.strip, file.readlines()))
  6. lights = np.zeros((6, 50), dtype=bool)
  7. for line in lines:
  8. words = line.split(' ')
  9. i, j = map(int, re.search(r'([0-9]+)(?: by |x)([0-9]+)', line).groups())
  10. if words[0] == 'rect':
  11. lights[:j, :i] = 1
  12. elif words[1] == 'row':
  13. lights[i] = np.roll(lights[i], j)
  14. else:
  15. lights[:, i] = np.roll(lights[:, i], j)
  16. print("Part one: %s" % np.sum(lights))
  17. print("Part two:")
  18. print('\n'.join(''.join('\u2588' if p else ' ' for p in row) for row in lights))