This commit is contained in:
Peter Hudec 2023-12-01 09:05:08 +01:00
commit 47ada5671b
5 changed files with 1065 additions and 0 deletions

1000
01/input.txt Normal file

File diff suppressed because it is too large Load Diff

4
01/input_sample01.txt Normal file
View File

@ -0,0 +1,4 @@
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet

7
01/input_sample02.txt Normal file
View File

@ -0,0 +1,7 @@
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen

16
01/part01.py Normal file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env python
from sys import stdin
import re
def read_line():
for line in stdin:
yield line
sum = 0
for line in read_line():
digits = re.sub("[^\d]", "", line)
sum += int(digits[0] + digits[-1])
print(sum)

38
01/part02.py Normal file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env python
from sys import stdin
import re
nums = {
'one': '1',
'two': '2',
'three': '3',
'four': '4',
'five': '5',
'six': '6',
'seven': '7',
'eight': '8',
'nine': '9'
}
def read_line():
for line in stdin:
yield line.strip()
def check_number_start(line):
for k,v in nums.items():
if line.startswith(k):
return v
return None
sum = 0
for line in read_line():
for i in range(len(line)):
f = check_number_start(line[i:])
if f is not None:
line = line[:i] + f + line[i + 1:]
digits = re.sub("[^\d]", "", line)
sum += int(digits[0] + digits[-1])
print(sum)