main
HeNine 10 months ago
parent 466c076d44
commit f8d8d1d559

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

File diff suppressed because it is too large Load Diff

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

File diff suppressed because it is too large Load Diff

@ -0,0 +1,19 @@
def process_line(line):
f = None
for char in line:
if char in "0123456789":
if not f:
f = char
l = char
return int("".join([f, l]))
with open("day01/data/input100.txt") as infile:
result = sum(map(process_line, infile))
print(result)
print(result == 142)
with open("day01/data/input101.txt") as infile:
result = sum(map(process_line, infile))
print(result)
print(result == 54968)

@ -0,0 +1,49 @@
import re
NUMBERS = re.compile(r"([0-9]|zero|one|two|three|four|five|six|seven|eight|nine)")
NUMBERS_MAP = dict(
zip(
list(map(str, range(0, 10)))
+ [
"zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
],
list(range(0, 10)) + list(range(0, 10)),
)
)
def process_line(line):
first = None
match = re.search(NUMBERS, line)
while match:
line = line[(match.start() + 1) :]
if not first:
first = NUMBERS_MAP[match.group(1)]
last = NUMBERS_MAP[match.group(1)]
match = re.search(NUMBERS, line)
return 10 * first + last
with open("day01/data/input200.txt") as infile:
result = sum(map(process_line, infile))
print(result)
print(result == 281)
with open("day01/data/input201.txt") as infile:
result = sum(map(process_line, infile))
print(result)
print(result == 54094)
Loading…
Cancel
Save