-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday_template.py
More file actions
67 lines (50 loc) · 1.73 KB
/
day_template.py
File metadata and controls
67 lines (50 loc) · 1.73 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from argparse import ArgumentParser
import doctest
from pathlib import Path
from typing import List
DEFAULT_INPUT_FILE_PATH = ""
def main_1(parsed_input) -> None:
return None
def main_2(parsed_input) -> None:
return None
def parse_input(input_path: Path) -> List:
if not input_path.exists():
print(f"Bad input path. '{input_path}' does not exist.")
return []
input_text: str = input_path.read_text()
# process input here
return []
def build_arg_parser() -> ArgumentParser:
arg_parser = ArgumentParser()
arg_parser.add_argument(
"-i", "--input", help="Path for input file", default=DEFAULT_INPUT_FILE_PATH
)
arg_parser.add_argument("-r", "--run", help="Run the solution", action="store_true")
arg_parser.add_argument(
"-t", "--test", help="Run the tests for this solution", action="store_true"
)
return arg_parser
def run(arg_parser: ArgumentParser) -> None:
args = arg_parser.parse_args()
if args.test:
print("Running Tests...")
failures, num_tests = doctest.testmod()
if not failures:
print(f"Ran {num_tests} test, 0 failures")
else:
return
if not args.test or args.run:
print("Parsing input...")
parsed_input = parse_input(Path(args.input))
if not parsed_input:
print("Could not parse input.")
return
print("Computing answer for part 1...")
answer_1 = main_1(parsed_input)
print(f"Answer for part 1: {answer_1}")
print("Computing answer for part 2...")
answer_2 = main_2(parsed_input)
print(f"Answer for part 2: {answer_2}")
if __name__ == "__main__":
parser = build_arg_parser()
run(parser)