add remaining code and input files from 2020
This commit is contained in:
1 parent
c10382b0c0
commit
23b2e01280
41 files changed
+11320
-37
No files matched your search
@@ -0,0 +1,54 @@
|
||||
from numpy import prod
|
||||
|
||||
|
||||
def find_earliest_bus(start, buses):
|
||||
i = start
|
||||
next = 0
|
||||
for time in buses:
|
||||
if time == 'x':
|
||||
pass
|
||||
elif int(time) - start % int(time) < i:
|
||||
i = int(time) - (start % int(time))
|
||||
next = int(time)
|
||||
return next * i
|
||||
|
||||
|
||||
def time_to_bus(start, bus):
|
||||
i = -start % bus
|
||||
return i
|
||||
|
||||
|
||||
def find_earliest_timestamp(timestamps):
|
||||
dict = {}
|
||||
for i in range(0, len(timestamps)):
|
||||
if timestamps[i] == 'x':
|
||||
pass
|
||||
else:
|
||||
line = int(timestamps[i])
|
||||
dict[line] = i
|
||||
|
||||
t = 0
|
||||
kgV = 1
|
||||
for bus, wait in dict.items():
|
||||
while not time_to_bus(t, bus) == (wait % bus):
|
||||
t += kgV
|
||||
kgV = kgV * bus
|
||||
return t
|
||||
|
||||
#for n in range(1352008337, 1000000000000000000):
|
||||
# ar = [(n + dict[b]) % b == 0 for b in dict.keys()]
|
||||
# if False not in ar:
|
||||
# return n
|
||||
# print(n)
|
||||
|
||||
|
||||
with open(r"C:\Users\Maya\Desktop\Uni\WS_2021\AoC\input13") as f:
|
||||
lines = f.readlines()
|
||||
lines[0] = int(lines[0])
|
||||
lines[1] = lines[1].split(",")
|
||||
|
||||
print(find_earliest_bus(lines[0], lines[1]))
|
||||
|
||||
print(find_earliest_timestamp(lines[1]))
|
||||
|
||||
|
||||
Reference in new issue
Block a user