Day 01

mail@pastecode.io avatar
unknown
python
7 months ago
481 B
7
Indexable
Never
import re

def calibrate(path) -> int:
    
    with open(path, 'r') as f:
        calibration_file = f.read().splitlines()

        combinations = []
        for i in calibration_file:
            digits = [_ for _ in re.findall('\d', i)]
            couple = ''.join([digits[0], digits[-1]])
            combinations.append(int(couple))
        
        return sum(combinations)


assert calibrate('./data/calibration_test.txt') == 142

print(calibrate('./data/calibration.txt'))
Leave a Comment