Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 304740a

Browse filesBrowse files
committed
day 25
1 parent 51cb616 commit 304740a
Copy full SHA for 304740a

File tree

3 files changed

+8
-30
lines changed
Filter options

3 files changed

+8
-30
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
|[22](https://adventofcode.com/2020/day/22)|Crab Combat|[py](/day22/main.py)|
2727
|[23](https://adventofcode.com/2020/day/23)|Crab Cups|[py](/day23/main.py)|
2828
|[24](https://adventofcode.com/2020/day/24)|Lobby Layout|[py](/day24/main.py)|
29-
|[25](https://adventofcode.com/2020/day/25)|Combo Breaker|[py](/day25/main.py), [alt](/day25/alt.py)|
29+
|[25](https://adventofcode.com/2020/day/25)|Combo Breaker|[py](/day25/main.py)|

‎day25/alt.py

Copy file name to clipboardExpand all lines: day25/alt.py
-10Lines changed: 0 additions & 10 deletions
This file was deleted.

‎day25/main.py

Copy file name to clipboard
+7-19Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
with open("input.txt") as f:
2-
public_key_card, public_key_door = [int(x.strip()) for x in f]
2+
pub1, pub2 = [int(x) for x in f]
33

4-
def calc_loop_size(public_key):
5-
subject_number = 7
6-
n = 1
7-
i = 0
8-
while True:
9-
n = (n * subject_number) % 20201227
10-
if n == public_key:
11-
return i+1
12-
i += 1
4+
n = 1
5+
loop_size = 0
6+
while n != pub2:
7+
n = (n * 7) % 20201227
8+
loop_size += 1
139

14-
def calc_encryption_key(subject_number, loop_size):
15-
n = 1
16-
for i in range(loop_size):
17-
n = (n * subject_number) % 20201227
18-
return n
19-
20-
loop_size = calc_loop_size(public_key_card)
21-
enc_key = calc_encryption_key(public_key_door, loop_size)
22-
print(enc_key)
10+
print(pow(pub1, loop_size, 20201227))

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.