From 91da124cf70f3e2f34774d85633d741863b4d854 Mon Sep 17 00:00:00 2001 From: Andrew Ekstedt Date: Thu, 22 Dec 2022 21:54:37 -0800 Subject: [PATCH] day 23 python part 2 --- day23/sol.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/day23/sol.py b/day23/sol.py index 6161270..658c21f 100644 --- a/day23/sol.py +++ b/day23/sol.py @@ -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)