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.

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