with open('input.text', 'r') as file: data: list[str] = file.readlines() # Parse Input left = [] right = [] for line in data: nums = line.split() left.append(int(nums[0])) right.append(int(nums[1])) # Part 1 lc = left.copy() rc = right.copy() total = 0 while min(lc) != float('inf'): lowest_left = min(lc) lowest_right = min(rc) total += abs(lowest_left - lowest_right) lc[lc.index(lowest_left)] = float('inf') rc[rc.index(lowest_right)] = float('inf') print(f'Part 1: {total}') # Part 2 lc = left.copy() rc = right.copy() total = 0 for i in range(0, len(lc)): lowest_left = min(lc) total += lowest_left * rc.count(lowest_left) lc.pop(lc.index(lowest_left)) print(f'Part 2: {total}')