Add day 1 part 1 (in python)

This commit is contained in:
askiiart 2023-12-05 07:41:42 -06:00
commit 81d1139474
Signed by untrusted user who does not match committer: askiiart
GPG key ID: BC3800E55FB54D67
3 changed files with 1039 additions and 0 deletions

20
day-1/day-1.py Executable file
View file

@ -0,0 +1,20 @@
#!/usr/bin/env python3
with open('day-1/input', 'rt') as f:
numbers = []
for line in f:
for char in line:
if str.isdigit(char):
digit1 = char
break
for i in range(len(line) - 2, -1, -1):
if str.isdigit(line[i]):
digit2 = line[i]
break
numbers.append(int(digit1 + digit2))
total = 0
for num in numbers:
total += num
print(total)

1000
day-1/input Normal file

File diff suppressed because it is too large Load diff

19
day-1/readme.md Normal file
View file

@ -0,0 +1,19 @@
1. Combine the first and last digit on each line to create a single two-digit number.
2. Get the sum of all of those
Input:
```txt
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet
```
(12, 38, 15, 77)
Output:
```txt
142
```