@@ -70,8 +70,8 @@ def calculate_spread(polymer: str) -> int:
7070# How about a smarter not harder approach instead
7171def non_brute_deconstruct (template : str , rules : dict [str , str ], n_cycles : int ) -> int :
7272 """Calculate the element spread of the provided polymer after the target insertion cycle(s)."""
73- l : str
74- r : str
73+ left : str
74+ right : str
7575
7676 # Since we don't care about order, we can keep track of the pairs created by each step and
7777 # use these counts to determine element counts once we run through all of the insertion cycles
@@ -80,12 +80,12 @@ def non_brute_deconstruct(template: str, rules: dict[str, str], n_cycles: int) -
8080 for _ in range (n_cycles ):
8181 updated_pairs : Counter [str ] = Counter ()
8282 for pair , count in pairs_counter .items ():
83- l , r = pair
83+ left , right = pair
8484 # Each pair will add the corresponding number of pairs composed of the inserted element
8585 # and the left/right sides
8686 # This will end up double counting the middle element but we can fix that later
87- updated_pairs [f"{ l } { rules [pair ]} " ] += count
88- updated_pairs [f"{ rules [pair ]} { r } " ] += count
87+ updated_pairs [f"{ left } { rules [pair ]} " ] += count
88+ updated_pairs [f"{ rules [pair ]} { right } " ] += count
8989
9090 # Now that we've updated our pairs we can replace our starting point
9191 pairs_counter = updated_pairs
@@ -94,9 +94,9 @@ def non_brute_deconstruct(template: str, rules: dict[str, str], n_cycles: int) -
9494 # quantities. As noted above, our inserted elements have all been double counted, except for the
9595 # first & last elements. So we can just double the first & last and divide the counts by 2.
9696 element_counts : Counter [str ] = Counter ()
97- for (l , r ), count in pairs_counter .items ():
98- element_counts [l ] += count
99- element_counts [r ] += count
97+ for (left , right ), count in pairs_counter .items ():
98+ element_counts [left ] += count
99+ element_counts [right ] += count
100100 element_counts [template [0 ]] += 1
101101 element_counts [template [- 1 ]] += 1
102102
0 commit comments