summaryrefslogtreecommitdiff
path: root/2020/aoc2020-d25.py
blob: 28d1afe2e6c79ca1f0d8b3a479a35009c2bd5fb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#advent of code 2020
#day 25
#I made a mistake by thinking that subject number is an unknow
#while in reality it actually is =7 as in puzzle description

def FindNumbers(pubkey):
	S = 7;
	L = 0;
	v = 1;
	while True:
		L += 1;
		v *= S;
		v = v%20201227;
		if v == pubkey:
			return L; #gives loop number

PuzzleInput = open("25.in","r").read().split("\n");
cardkey = int(PuzzleInput[0]);
doorkey = int(PuzzleInput[1]);
#encryption key is the same 
#whether we use loop of card + subject of door
#or loop of door + subject of card
encryption = 1;
for l in range(FindNumbers(cardkey)):
	encryption *= doorkey;
	encryption = encryption%20201227;

part1 = encryption; 
print("part 1 =", part1);