Simplify day 5 further

This commit is contained in:
Sijmen 2023-12-06 01:42:20 +01:00
parent 5cde3ab3b9
commit 8433c88147

View file

@ -33,34 +33,24 @@ def transform_ranges(map, ranges):
yield from transform_ranges(map, [(src_end, end - src_end)])
def do_the_thing(ranges):
soils = transform_ranges(seed_to_soil, ranges)
ferts = transform_ranges(soil_to_fert, soils)
waters = transform_ranges(fert_to_water, ferts)
lights = transform_ranges(water_to_light, waters)
temps = transform_ranges(light_to_temp, lights)
humids = transform_ranges(temp_to_humid, temps)
locs = transform_ranges(humid_to_loc, humids)
(loc, _) = min(locs)
return loc
def do_the_thing(maps, ranges):
for map in maps:
ranges = transform_ranges(map, ranges)
return min(ranges)[0]
def main():
input = fileinput.input()
seeds = [int(seed) for seed in next(input).split()[1:]]
next(input)
next(input)
seed_to_soil = list(parse_map(input))
soil_to_fert = list(parse_map(input))
fert_to_water = list(parse_map(input))
water_to_light = list(parse_map(input))
light_to_temp = list(parse_map(input))
temp_to_humid = list(parse_map(input))
humid_to_loc = list(parse_map(input))
maps = [list(parse_map(input)) for _ in range(7)]
part1 = do_the_thing((seed, 1) for seed in seeds)
part2 = do_the_thing(zip(*(iter(seeds),) * 2))
part1 = do_the_thing(maps, ((seed, 1) for seed in seeds))
part2 = do_the_thing(maps, zip(*[iter(seeds)] * 2))
print(part1, part2)
main()