from helpers import Helper helper = Helper(debug=True) debug = helper.debug load_input = helper.load_input def main(): from string import digits input_lines = load_input(1) # The calibration value of each line is the first and last digit # in each line, in order, combined to make a two-digit number. calibrations = [] for line in input_lines: line = line.strip() if line == "": continue first = "" last = "" for i, char in enumerate(line): if char in digits: # print(f"Found first digit in {line} at position {i}: {char}") first = char break for i, char in enumerate(line[::-1]): if char in digits: # print(f"Found last digit in {line} at position {len(line) - i}: {char}") last = char break calibrations.append(int(first + last)) print(calibrations) # The total calibration value is the sum of the individual # calibration values. print(f"Total calibration value: {sum(calibrations)}") if __name__ == "__main__": main()