From d82dcaa421cec4535e48ef58a4df9d826d057255 Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Wed, 23 Dec 2020 11:41:36 +0100 Subject: [PATCH 1/3] day23: don't need left --- day23.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) 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 From 3a396c8c47b229dd4d55eaf6bb07484b412f27f1 Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Wed, 23 Dec 2020 12:54:10 +0100 Subject: [PATCH 2/3] day23: correct naming --- day23.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/day23.py b/day23.py index b9e6ee7..241633f 100644 --- a/day23.py +++ b/day23.py @@ -11,7 +11,7 @@ class Cup: self.right = right -def buildDoubleLinkedListDict(cup_list): +def buildLinkedListDict(cup_list): cups = {} left_cup = None first_cup = None @@ -47,7 +47,7 @@ def play(cups, current_cup, max_label): def part1(test_mode=False): my_input = aoclib.getInputAs2DArray(day=DAY, return_type=int, test=test_mode) - cups, current_cup = buildDoubleLinkedListDict(my_input[0]) + cups, current_cup = buildLinkedListDict(my_input[0]) for _ in range(100): cups, current_cup = play(cups, current_cup, 9) @@ -63,7 +63,7 @@ def part1(test_mode=False): def part2(test_mode=False): my_input = aoclib.getInputAs2DArray(day=DAY, return_type=int, test=test_mode) - cups, current_cup = buildDoubleLinkedListDict(my_input[0] + list(range(max(my_input[0]) + 1, 1000001))) + cups, current_cup = buildLinkedListDict(my_input[0] + list(range(max(my_input[0]) + 1, 1000001))) for _ in range(10000000): cups, current_cup = play(cups, current_cup, 1000000) From 153f4f79b6ca4227d9430228528ffc23cbf07d36 Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Wed, 23 Dec 2020 13:51:59 +0100 Subject: [PATCH 3/3] TIL: python has 1000 delimiters --- day23.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/day23.py b/day23.py index 241633f..716ba72 100644 --- a/day23.py +++ b/day23.py @@ -63,9 +63,9 @@ def part1(test_mode=False): def part2(test_mode=False): my_input = aoclib.getInputAs2DArray(day=DAY, return_type=int, test=test_mode) - cups, current_cup = buildLinkedListDict(my_input[0] + list(range(max(my_input[0]) + 1, 1000001))) + cups, current_cup = buildLinkedListDict(my_input[0] + list(range(max(my_input[0]) + 1, 1_000_001))) - for _ in range(10000000): - cups, current_cup = play(cups, current_cup, 1000000) + for _ in range(10_000_000): + cups, current_cup = play(cups, current_cup, 1_000_000) return cups[1].right.label * cups[1].right.right.label