day 23 python part 2

main
magical 2022-12-22 21:54:37 -08:00
parent 8c0cd8e300
commit 91da124cf7
1 changed files with 13 additions and 5 deletions

View File

@ -35,9 +35,9 @@ def neighbors(pos):
def migrate(start, rounds):
moves = ['N', 'S', 'W', 'E']
for _ in range(rounds):
show(start)
print("-")
for i in range(rounds):
#show(start)
#print("-")
propose = {}
destCount = Counter()
@ -52,15 +52,20 @@ def migrate(start, rounds):
break
next = {}
moved = 0
for p, d in propose.items():
if destCount[d] <= 1:
next[d] = 1
moved += p != d
else:
next[p] = 1
if not moved:
break
moves.append(moves.pop(0))
start = next
return start
return start, i+1
def show(pos):
xmin = min(x for x,y in pos)
@ -80,5 +85,8 @@ def count_empty(pos):
#print(pos)
n = count_empty(migrate(pos, 10))
end, _ = migrate(pos, 10)
print(count_empty(end))
_, n = migrate(pos, 100000)
print(n)