-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_day.py
140 lines (116 loc) · 3.86 KB
/
setup_day.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import os
import datetime
def setup_day(day=None, year=None):
"""
Creates the folder and files for the specified day and year, including solution.py,
input.txt, and test_dayXX.py. Defaults to today's day and year if not specified.
"""
# Determine the year
if year is None:
year = datetime.datetime.now().year
elif isinstance(year, str):
try:
year = int(year)
except ValueError:
raise ValueError("Year must be an integer or a string that can be converted to an integer.")
# Determine the day
if day is None:
day = datetime.datetime.now().day
elif isinstance(day, str):
try:
day = int(day)
except ValueError:
raise ValueError("Day must be an integer or a string that can be converted to an integer.")
# Validate inputs
if not (1 <= day <= 25):
raise ValueError("Day must be between 1 and 25.")
if not (2015 <= year <= datetime.datetime.now().year):
raise ValueError(f"Year must be between 2015 and {datetime.datetime.now().year} (inclusive).")
# Create the folder structure
day_folder = f"{year}/day{day:02d}"
os.makedirs(day_folder, exist_ok=True)
# Create empty __init__.py files in relevant folders
for folder in [str(year), day_folder]:
init_path = os.path.join(folder, "__init__.py")
if not os.path.exists(init_path):
with open(init_path, "w") as f:
f.write("") # Create an empty __init__.py file
# File paths
input_file = os.path.join(day_folder, "input.txt")
solution_file = os.path.join(day_folder, "solution.py")
test_file = os.path.join(day_folder, f"test_day{day:02d}.py")
# Create input.txt
if not os.path.exists(input_file):
with open(input_file, "w") as f:
f.write("") # Empty file for input
# Create solution.py
if not os.path.exists(solution_file):
with open(solution_file, "w") as f:
f.write(f"""import re
import numpy as np
from collections import Counter
from itertools import accumulate, product, permutations, combinations
from utils.file_io import read_input
from utils.timer import timer
import os
@timer
def solve_part1(input_data):
\"\"\"
Solves Part 1 of the puzzle.
Args:
input_data (str): The raw input data as a string.
Returns:
Any: The solution to Part 1.
\"\"\"
# Add your solution logic here
return None
@timer
def solve_part2(input_data):
\"\"\"
Solves Part 2 of the puzzle.
Args:
input_data (str): The raw input data as a string.
Returns:
Any: The solution to Part 2.
\"\"\"
# Add your solution logic here
return None
if __name__ == "__main__":
script_dir = os.path.dirname(os.path.abspath(__file__))
input_data = read_input("input.txt", base_path=script_dir)
print("Solution to Part 1:", solve_part1(input_data))
print("Solution to Part 2:", solve_part2(input_data))
""")
# Create test_dayXX.py
if not os.path.exists(test_file):
with open(test_file, "w") as f:
f.write(f"""import pytest
from day{day:02d}.solution import solve_part1, solve_part2
import os
def test_solve_part1():
input_data = \"\"\"1
2
3
4\"\"\" # Example input
expected_output = None # Replace with the expected output
assert solve_part1(input_data) == expected_output
def test_solve_part2():
input_data = \"\"\"1
2
3
4\"\"\" # Example input
expected_output = None # Replace with the expected output
assert solve_part2(input_data) == expected_output
""")
print(f"Setup complete for Year {year}, Day {day:02d}")
if __name__ == "__main__":
import sys
# Parse command-line arguments
args = sys.argv[1:]
day = None
year = None
if len(args) >= 1:
day = args[0]
if len(args) == 2:
year = args[1]
setup_day(day, year)