-
Notifications
You must be signed in to change notification settings - Fork 0
/
day20.py
57 lines (46 loc) · 1.83 KB
/
day20.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
import numpy as np
f = open("ressources/day20.txt", "r")
lines = f.readlines()
encryptedList = []
for line in lines:
encryptedList.append(int(line.replace("\n", "")))
decryptedList = [(encryptedList[i], i) for i in range(len(encryptedList))]
length = len(encryptedList)-1
for i in range(len(encryptedList)):
elem = encryptedList[i]
index = decryptedList.index((elem,i))
poppedElement = decryptedList.pop(index)
if index+elem == 0:
decryptedList.append(poppedElement)
else:
decryptedList.insert((index+elem) % length, poppedElement)
elem0 = (0, encryptedList.index(0))
position0 = decryptedList.index(elem0)
elem1 = decryptedList[(position0+1000)%(length+1)][0]
elem2 = decryptedList[(position0+2000)%(length+1)][0]
elem3 = decryptedList[(position0+3000)%(length+1)][0]
print(elem1, elem2, elem3)
print("Grove coordinate is: {}".format(elem1+elem2+elem3))
encryptedList = []
for line in lines:
encryptedList.append(int(line.replace("\n", "")))
encryptedList = [elem*811589153 for elem in encryptedList]
decryptedList = [(encryptedList[i], i) for i in range(len(encryptedList))]
length = len(encryptedList)-1
for _ in range(10):
for i in range(len(encryptedList)):
elem = encryptedList[i]
index = decryptedList.index((elem,i))
poppedElement = decryptedList.pop(index)
if index+elem == 0:
decryptedList.append(poppedElement)
else:
decryptedList.insert((index+elem) % length, poppedElement)
elem0 = (0, encryptedList.index(0))
position0 = decryptedList.index(elem0)
elem1 = decryptedList[(position0+1000)%(length+1)][0]
elem2 = decryptedList[(position0+2000)%(length+1)][0]
elem3 = decryptedList[(position0+3000)%(length+1)][0]
print(elem1, elem2, elem3)
print("Grove coordinate is: {}".format(elem1+elem2+elem3))