Solutions to Advent of Code 2017 https://adventofcode.com/2017/
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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)}')