-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaoc.py
69 lines (53 loc) · 1.42 KB
/
aoc.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
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
68
69
"""Advent of code runner
Usage:
aoc.py day <day_number> [--timed]
aoc.py generate <day_number>
aoc.py (-h | --help)
aoc.py --version
Options:
-h --help Show this screen.
--version Show version.
--timed Run with timer
"""
from docopt import docopt
import importlib
import time
import sys
import os
def day(args):
try:
i = importlib.import_module(f"{args['<day_number>']}.solution", package=".")
except Exception:
print("No such day available")
sys.exit(1)
a = time.time()
print(i.part_1())
if args['--timed']:
print(f"Part 1 Solution time: {time.time()-a} seconds")
b = time.time()
print(i.part_2())
if args['--timed']:
print(f"Part 2 Solution time: {time.time()-b} seconds")
def generate(args):
path = os.path.join(os.path.dirname(__file__), args['<day_number>'])
if os.path.exists(path):
print("Day already exists")
return
os.makedirs(args['<day_number>'])
with open(f"{args['<day_number>']}/input.txt", 'w') as f:
pass
with open(f"{args['<day_number>']}/solution.py", 'w') as f:
f.write(f"""# Advent of Code, Day {args['<day_number>']}
import os
input_path = os.path.join(os.path.dirname(__file__), "input.txt")
def part_1():
pass
def part_2():
pass
""")
if __name__ == '__main__':
args = docopt(__doc__, version='Advent of Code runner 1.0')
if args['day']:
day(args)
elif args['generate']:
generate(args)