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

13.py 737B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/python3
  2. import itertools
  3. input = 1364
  4. high = lambda x: sum([1 for d in bin(x) if d == '1'])
  5. wall = lambda x, y: high(x*x + 3*x + 2*x*y + y + y*y + input) % 2 == 1
  6. all_moves = lambda x, y: [(x-1, y), (x+1, y), (x, y-1), (x, y+1)]
  7. moves = lambda x, y: (m for m in all_moves(x, y) if m[0] >= 0 and m[1] >= 0 and not wall(*m))
  8. queue = {(1, 1)}
  9. visited = set()
  10. distance = {}
  11. steps = 0
  12. while steps < 100:
  13. for c in queue:
  14. if c not in distance:
  15. distance[c] = steps
  16. visited = visited.union(queue)
  17. next_queue = set(itertools.chain.from_iterable(moves(*c) for c in queue)) - visited
  18. queue = next_queue
  19. steps += 1
  20. print("Part 1: %s" % distance[(31, 39)])
  21. print("Part 2: %s" % sum(1 for s in distance.values() if s <= 50))