day25 the solution is easier to calculate once you have the loop count
This commit is contained in:
parent
d630a568b7
commit
97d51cb00c
8
day25.py
8
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):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user