From 97d51cb00cc741b7550ac7b258b239a2e60ee330 Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Fri, 25 Dec 2020 07:45:40 +0100 Subject: [PATCH] day25 the solution is easier to calculate once you have the loop count --- day25.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/day25.py b/day25.py index 3704133..2541cbc 100644 --- a/day25.py +++ b/day25.py @@ -15,15 +15,17 @@ def transform(key, subject_number, loop_size=1): def part1(test_mode=False): my_input = aoclib.getInputAsArray(day=DAY, return_type=int, test=test_mode) - loop_card = 0 + loop_card = 1 public_key_card = 1 - while public_key_card != my_input[0]: + while pow(7, loop_card, 20201227) != my_input[0]: loop_card += 1 public_key_card = transform(public_key_card, 7) public_key_door = my_input[1] - return transform(1, public_key_door, loop_card) + # as we start with a key of 1, it's just a matter of + # multiplying public_key_door with itself loop_card times .... + return pow(public_key_door, loop_card, 20201227) def part2(test_mode=False):