-
Notifications
You must be signed in to change notification settings - Fork 0
/
part1.py
25 lines (20 loc) · 821 Bytes
/
part1.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
with open('input.txt') as file:
seeds = list(map(int, file.readline().split(':')[1].split()))
mappings = {}
for line in filter(None, map(str.strip, file)):
if line.endswith(':'):
source, dest = line.split()[0].split('-to-')
mappings[source] = [dest, []]
else:
mappings[source][1].append(list(map(int, line.split())))
objects = {'seed': seeds}
for source, (dest, mapping) in mappings.items():
objects[dest] = []
for obj in objects[source]:
for dest_start, source_start, range_length in mapping:
if source_start <= obj < source_start + range_length:
objects[dest].append(obj + dest_start - source_start)
break
else:
objects[dest].append(obj)
print(min(objects['location']))