Add day 1 part 1 (in python)
This commit is contained in:
commit
81d1139474
3 changed files with 1039 additions and 0 deletions
20
day-1/day-1.py
Executable file
20
day-1/day-1.py
Executable 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
1000
day-1/input
Normal file
File diff suppressed because it is too large
Load diff
19
day-1/readme.md
Normal file
19
day-1/readme.md
Normal 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
|
||||
```
|
Loading…
Reference in a new issue