day 23 python part 2
parent
8c0cd8e300
commit
91da124cf7
18
day23/sol.py
18
day23/sol.py
|
@ -35,9 +35,9 @@ def neighbors(pos):
|
||||||
|
|
||||||
def migrate(start, rounds):
|
def migrate(start, rounds):
|
||||||
moves = ['N', 'S', 'W', 'E']
|
moves = ['N', 'S', 'W', 'E']
|
||||||
for _ in range(rounds):
|
for i in range(rounds):
|
||||||
show(start)
|
#show(start)
|
||||||
print("-")
|
#print("-")
|
||||||
propose = {}
|
propose = {}
|
||||||
destCount = Counter()
|
destCount = Counter()
|
||||||
|
|
||||||
|
@ -52,15 +52,20 @@ def migrate(start, rounds):
|
||||||
break
|
break
|
||||||
|
|
||||||
next = {}
|
next = {}
|
||||||
|
moved = 0
|
||||||
for p, d in propose.items():
|
for p, d in propose.items():
|
||||||
if destCount[d] <= 1:
|
if destCount[d] <= 1:
|
||||||
next[d] = 1
|
next[d] = 1
|
||||||
|
moved += p != d
|
||||||
else:
|
else:
|
||||||
next[p] = 1
|
next[p] = 1
|
||||||
|
|
||||||
|
if not moved:
|
||||||
|
break
|
||||||
|
|
||||||
moves.append(moves.pop(0))
|
moves.append(moves.pop(0))
|
||||||
start = next
|
start = next
|
||||||
return start
|
return start, i+1
|
||||||
|
|
||||||
def show(pos):
|
def show(pos):
|
||||||
xmin = min(x for x,y in pos)
|
xmin = min(x for x,y in pos)
|
||||||
|
@ -80,5 +85,8 @@ def count_empty(pos):
|
||||||
|
|
||||||
|
|
||||||
#print(pos)
|
#print(pos)
|
||||||
n = count_empty(migrate(pos, 10))
|
end, _ = migrate(pos, 10)
|
||||||
|
print(count_empty(end))
|
||||||
|
|
||||||
|
_, n = migrate(pos, 100000)
|
||||||
print(n)
|
print(n)
|
||||||
|
|
Loading…
Reference in New Issue