diff --git a/day23.py b/day23.py index 96a6218..b9e6ee7 100644 --- a/day23.py +++ b/day23.py @@ -6,9 +6,8 @@ TEST_SOLUTION_PART2 = 149245887792 class Cup: - def __init__(self, label, left=None, right=None): + def __init__(self, label, right=None): self.label = label - self.left = left self.right = right @@ -17,7 +16,7 @@ def buildDoubleLinkedListDict(cup_list): left_cup = None first_cup = None for cup in cup_list: - thisCup = Cup(cup, left_cup, None) + thisCup = Cup(cup, None) if first_cup is None: first_cup = thisCup else: @@ -25,7 +24,6 @@ def buildDoubleLinkedListDict(cup_list): left_cup = thisCup cups[cup] = thisCup - first_cup.left = thisCup thisCup.right = first_cup return cups, first_cup @@ -35,18 +33,14 @@ def play(cups, current_cup, max_label): first_pickup = current_cup.right first_after_pickup = current_cup.right.right.right.right current_cup.right = first_after_pickup - first_after_pickup.left = current_cup destination_label = current_cup.label - 1 if current_cup.label > 1 else max_label while destination_label in [first_pickup.label, first_pickup.right.label, first_pickup.right.right.label]: destination_label = destination_label - 1 if destination_label > 1 else max_label desination_cup = cups[destination_label] - desination_right = desination_cup.right + first_pickup.right.right.right = desination_cup.right desination_cup.right = first_pickup - first_pickup.left = desination_cup - desination_right.left = first_pickup.right.right - first_pickup.right.right.right = desination_right return cups, current_cup.right