Skip to content

Commit

Permalink
2023 day 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Justintime50 committed Dec 1, 2023
1 parent 40ac4cd commit 6f917fa
Show file tree
Hide file tree
Showing 6 changed files with 1,107 additions and 0 deletions.
41 changes: 41 additions & 0 deletions adventofcode/_2023/day1/challenge.py
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()
Loading

0 comments on commit 6f917fa

Please sign in to comment.