Solutions to Advent of Code 2017 https://adventofcode.com/2017/
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.

14.py 558B

123456789101112131415
  1. import functools
  2. from shared import knot_hash, add_connected_components
  3. with open('data/14.txt', 'r') as file:
  4. seed = file.readline().strip()
  5. grid = [bin(int(knot_hash(f'{seed}-{i}'), 16))[2:].zfill(128) for i in range(128)]
  6. print(f'Part one: {sum(row.count("1") for row in grid)}')
  7. regions = []
  8. for y, row in enumerate(grid):
  9. for x, cell in enumerate(row):
  10. if cell == '1':
  11. add_connected_components(regions, [(x-1, y), (x, y-1), (x+1, y), (x, y+1)], {(x, y)})
  12. print(f'Part two: {len(regions)}')