def do_task(input): insplit = input.split("\n\n") seeds = [int(s) for s in insplit[0].split()[1:]] maps = [parse_map(s) for s in insplit[1:]] mapped_seeds = [] for n in seeds: for m in maps: n = map_number(n,m) mapped_seeds.append(n) return min(mapped_seeds) def parse_map(mapstring): maps = [] for ms in mapstring.split("\n")[1:]: maps.append(tuple(int(a) for a in ms.split())) return maps def map_number(n, m): for (d, s, l) in m: if n >= s and n <= s+l-1: return d + n - s return n with open("day05/data/input100.txt") as infile: result = do_task(infile.read()) print(result) print(result == 35) with open("day05/data/input101.txt") as infile: result = do_task(infile.read()) print(result) print(result == 424490994)