Created
December 2, 2023 07:49
-
-
Save kaskajp/92ab4f45e6a08de2c553b48e92e1979e to your computer and use it in GitHub Desktop.
AoC 2023 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_first_digit(str): | |
for char in str: | |
if char.isdigit(): | |
return char | |
return None | |
def get_last_digit(str): | |
for char in reversed(str): | |
if char.isdigit(): | |
return char | |
return None | |
total = 0 | |
with open('input.txt', 'r') as file: | |
for line in file: | |
combinedNr = get_first_digit(line) + get_last_digit(line) | |
total += int(combinedNr) | |
print(total, end='') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment