1
0

AOC Day 1 puzzle solved

This commit is contained in:
2023-12-02 15:17:41 +01:00
commit 3d212a0c85
6 changed files with 2079 additions and 0 deletions

1000
Day-1/Part 1/input.txt Normal file

File diff suppressed because it is too large Load Diff

32
Day-1/Part 1/solution.py Normal file
View File

@ -0,0 +1,32 @@
def findFirstDigitInString(string: str) -> str:
length_of_string = len(string)
i = 0
while i < length_of_string :
if ( string[i].isdigit()):
return string[i]
i+=1
numbers = []
with open("input.txt") as file:
line = file.readline()
while line:
firstdigit =findFirstDigitInString(line)
lastdigit = findFirstDigitInString(line[::-1]) # doing the same for the string in reverse will get the last digit
digit = firstdigit + lastdigit
digit = int(digit)
print(f"found: {digit}")
numbers.append(digit)
line = file.readline()
print(numbers)
# now we'll need to sum them
sum = 0
for n in numbers:
sum += n
print(f"sum: {sum}")