-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdayThirteen.py
38 lines (30 loc) · 873 Bytes
/
dayThirteen.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
import math
data = []
with open("dayThirteen.txt") as file:
for line in file.readlines():
line = line.rstrip()
data.append(line)
data[1] = data[1].split(",")
# # q1
cap = int(data[0])
vals = []
i = []
for v in data[1]:
try:
v = int(v)
vals.append(math.ceil(cap/v)*v)
i.append(v)
except :
pass
print((min(vals)-cap)*i[vals.index(min(vals))])
# q2
values = data[1]
for i in range(len(values)):
if values[i] != "x":
print(i, values[i])
# use chinese remainder theorem
# x is congruent to 0 mod values[0]
# x is congruent to -index mod values[i] (1 -> last index)
# I spotted the Chinese remainder theorem could be used while going through the example
# especially with how values[i] were all coprime
# However, I did not write code for this. I simply made use of an online calculator 😅