Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- total = 0
- with open("day1.txt") as f: # open the file, reading it
- for line in f.readlines(): # loop over each line in the file
- numbers = list(filter(str.isdigit, line)) # create a list of just the numbers in each line
- calibration = int(numbers[0] + numbers[-1]) # add the first and last to get the calibration value
- total += calibration # then add it to the total
- print(total)
Advertisement
Advertisement