You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
496 B
Python
23 lines
496 B
Python
4 years ago
|
import re
|
||
|
|
||
|
with open('input', 'r') as f:
|
||
|
arrival = int(f.readline())
|
||
|
buses = list(map(int, re.findall(r'[0-9]+', f.readline().strip())))
|
||
|
|
||
|
earliest = None
|
||
|
earliest_bus = None
|
||
|
|
||
|
print(f'{arrival=}')
|
||
|
|
||
|
for bus in buses:
|
||
|
wait = bus - arrival % bus
|
||
|
wait = 0 if wait == bus else wait
|
||
|
if earliest is None or wait < earliest:
|
||
|
earliest = wait
|
||
|
earliest_bus = bus
|
||
|
print(bus, wait)
|
||
|
|
||
|
print(f'{earliest=} {earliest_bus=}')
|
||
|
print('Solution')
|
||
|
print(earliest * earliest_bus)
|