-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.py
33 lines (23 loc) · 885 Bytes
/
common.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
import os
FOLDER = "inputs"
def getDayInput(day, part=1, test=False, blankLines=False):
"""
Reads the input file for the given day and returns its contents as a list of strings.
Parameters:
- day (int): The day for which to read the input file.
- part (int): Part 1 or 2 of the challenge. Defaults to 1.
- test (bool): Whether to read the test input file for that day. Defaults to False.
- blankLines (bool): Whether to include blank lines in the output. Defaults to False.
Returns:
- A list of strings (the lines of the input fule)
"""
if test:
fileName = f"day{str(day).zfill(2)}-test{part}.txt"
else:
fileName = f"day{str(day).zfill(2)}.txt"
filePath = os.path.join(FOLDER, fileName)
with open(filePath, "r") as f:
lines = f.read().splitlines()
if not blankLines:
lines = [line for line in lines if line] # remove blank lines
return lines