Skip to content

Instantly share code, notes, and snippets.

@kaskajp
Created December 2, 2023 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaskajp/92ab4f45e6a08de2c553b48e92e1979e to your computer and use it in GitHub Desktop.
Save kaskajp/92ab4f45e6a08de2c553b48e92e1979e to your computer and use it in GitHub Desktop.
AoC 2023 1
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