summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2021-12-17 20:10:11 +0000
committerTomasz Kramkowski <tk@the-tk.com>2021-12-17 20:10:11 +0000
commit0ef97e71485466e9982734f811a6fde4ebed1fca (patch)
tree9a5a1dfa81dee4f48426d8254dae00c83ae1c0ec
parent522edc867cc2bc6993da73701b0c13a538621700 (diff)
downloadaoc2021-0ef97e71485466e9982734f811a6fde4ebed1fca.tar.gz
aoc2021-0ef97e71485466e9982734f811a6fde4ebed1fca.tar.xz
aoc2021-0ef97e71485466e9982734f811a6fde4ebed1fca.zip
utils
-rw-r--r--utils.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/utils.py b/utils.py
index 00d0d60..8b688a6 100644
--- a/utils.py
+++ b/utils.py
@@ -4,6 +4,7 @@ from collections.abc import Iterable, Iterator
from dataclasses import dataclass
from itertools import islice
from math import sqrt
+from re import match as re_match
from sys import argv
from typing import TypeVar, Generic, Union, Optional, cast
@@ -73,3 +74,7 @@ def open_day(n: int):
if len(argv) == 2:
return open(argv[1])
return open(f'{n}.in')
+
+def parse_day(n: int, regex: str):
+ with open_day(n) as f:
+ return re_match(regex, f.read().rstrip()).groups()