Day 01 (minified)
This commit is contained in:
2
day01/part1.min.py
Normal file
2
day01/part1.min.py
Normal 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")))
|
||||
@@ -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)
|
||||
|
||||
@@ -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)})")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user