Skip to content

Latest commit

 

History

History
53 lines (37 loc) · 1.92 KB

README.md

File metadata and controls

53 lines (37 loc) · 1.92 KB

Day 1 - Trebuchet?! - Deciphering Calibration Values

Part One: Identifying Digits - Original Puzzle

You're tasked with deciphering calibration values hidden within a modified document. The calibration values are derived by extracting the first and last digits from each line and summing them up.

Example:

1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet

The calibration values of these four lines are 12, 38, 15, and 77. Adding these together produces 142.

Consider your entire calibration document. What is the sum of all of the calibration values?

My Solution - Input Data

from input_data import input_day_01 as file

sum = 0
for line in file:
    # Store each digit in line
    nums = [char for char in line if char in "0123456789"]
    
    # Use first and last digit to work out calibration value
    calibration_value = int(nums[0] + nums[-1])
    sum += calibration_value

print("Sum of all Calibration Values:", sum)

Part Two: Lettered Digits - Original Puzzle

After realizing that some digits are spelled out, you're required to identify the real first and last digits on each line.

Example:

two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen

The calibration values are 29, 83, 13, 24, 42, 14, and 76. Adding these together produces 281.

What is the sum of all of the calibration values?

My Solution - Input Data


< Back to all solutions