38 lines
713 B
Python
38 lines
713 B
Python
|
import shared
|
||
|
import re
|
||
|
from scanf import scanf
|
||
|
|
||
|
# @shared.profile
|
||
|
def part1(rows):
|
||
|
total = 0
|
||
|
r = re.compile(r'mul\(\d+,\d+\)')
|
||
|
for row in rows:
|
||
|
print(row)
|
||
|
muls = r.findall(row)
|
||
|
for m in muls:
|
||
|
x, y = scanf("mul(%d,%d)", m)
|
||
|
total += x * y
|
||
|
print(total)
|
||
|
|
||
|
|
||
|
|
||
|
# @shared.profile
|
||
|
def part2(rows):
|
||
|
pass
|
||
|
|
||
|
|
||
|
def main():
|
||
|
rows = [row for row in shared.load_rows(3)]
|
||
|
with shared.elapsed_timer() as elapsed:
|
||
|
part1(rows)
|
||
|
print("🕒", elapsed())
|
||
|
|
||
|
rows = [row for row in shared.load_rows(3, True)]
|
||
|
with shared.elapsed_timer() as elapsed:
|
||
|
part2(rows)
|
||
|
print("🕒", elapsed())
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|