Day 01 (minified)

This commit is contained in:
Sebastian Seedorf
2023-12-09 23:37:58 +01:00
parent aaecd0a396
commit 14c3375905
3 changed files with 5 additions and 5 deletions

2
day01/part1.min.py Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env python3
import re;print(sum(int(re.search("\d",l)[0]+re.search("\d",l[::-1])[0])for l in open("input.txt")))

View File

@@ -3,12 +3,11 @@ import re
lines = (x.strip() for x in open("input.txt"))
total = 0
regexFirst = re.compile(f"^.*?(\\d)")
regexLast = re.compile(f"^.*(\\d)")
regex = re.compile("\d")
for line in lines:
first = regexFirst.match(line).group(1)
last = regexLast.match(line).group(1)
first = regex.search(line)[0]
last = regex.search(line[::-1])[0]
total += int(first + last)
print(total)

View File

@@ -5,7 +5,6 @@ STRINGS = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine
lines = (x.strip() for x in open("input.txt"))
total = 0
digitRegex = f"(\\d|{'|'.join(STRINGS)})"
regexFirst = re.compile(f"^.*?(\\d|{'|'.join(STRINGS)})")
regexLast = re.compile(f"^.*(\\d|{'|'.join(STRINGS)})")