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