-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40ac4cd
commit 6f917fa
Showing
6 changed files
with
1,107 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from adventofcode.utils import open_input | ||
|
||
|
||
def main(): | ||
data = open_input('adventofcode/_2023/day1/input.txt') | ||
answer_1 = get_answer_1(data) | ||
# answer_2 = get_answer_2(data) | ||
|
||
print(answer_1) | ||
# print(answer_2) | ||
|
||
return answer_1 | ||
|
||
|
||
def get_answer_1(data): | ||
""" | ||
- get the first and last digit of each line, make a two digit number per line, sum all outcomes together | ||
""" | ||
sums = [] | ||
for _, line in enumerate(data): | ||
for char in line: | ||
if char.isdigit(): | ||
first = char | ||
break | ||
for char in line[::-1]: # Flip the line backwards as a naive way of getting the last digit in the line | ||
if char.isdigit(): | ||
last = char | ||
break | ||
|
||
newline = str(first) + str(last) | ||
|
||
sums.append(int(newline)) | ||
|
||
return sum(sums) | ||
|
||
|
||
|
||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.