You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

54 lines
1.2 KiB

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]))