Advertisement
Cazibear

aoc 2023 day 1 part 1

Dec 9th, 2023
802
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. total = 0
  2.  
  3. with open("day1.txt") as f: # open the file, reading it
  4.     for line in f.readlines(): # loop over each line in the file
  5.         numbers = list(filter(str.isdigit, line)) # create a list of just the numbers in each line
  6.         calibration = int(numbers[0] + numbers[-1]) # add the first and last to get the calibration value
  7.         total += calibration # then add it to the total
  8.  
  9. print(total)
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement