-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.py
32 lines (25 loc) · 866 Bytes
/
helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import pathlib
import traceback
from pprint import pprint as pp
from rich.traceback import install
install()
def inp(suffix=""):
"""
Most / all AoC tasks can read the inputs from one text file.
This function finds the input based on the python code filename in the
`input` directory. For instance, `dec03.py` will read inputs from
`input/dec03.txt`.
"""
callstack = traceback.extract_stack()
prev_frame = callstack[-2]
fname = pathlib.Path(prev_frame.filename).stem
code_file = pathlib.Path(fname)
here = code_file.parent
inputfile = here / "input" / f"{code_file.stem}{suffix}.txt"
print(f"AoC solution for {code_file.stem}")
return list(map(str.strip, inputfile.open("r").readlines()))
def p(*s):
"""
Print arguments with a dash between. Useful for debugging.
"""
print(*s, sep=" - ")