Skip to content

Commit bf73be6

Browse files
committed
fix(aoc): fix temp solutions and tests day 01/2015
1 parent 6044c36 commit bf73be6

File tree

5 files changed

+73
-35
lines changed

5 files changed

+73
-35
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import os
2+
from dotenv import load_dotenv
3+
from utils.ec_utils import get_input_file_path, read_input_file
4+
5+
load_dotenv()
6+
environment = os.getenv("ENVIRONMENT")
7+
8+
9+
def solve_01_2015(filename: str) -> tuple[int, int]:
10+
"""
11+
Solution of the Advent of Code 2015, Day 01: Not Quite Lisp.
12+
:param filename: filename that contains the input data
13+
:return: solution for each part (1, 2)
14+
"""
15+
try:
16+
# Create the absolute path of the input file
17+
input_file_path = get_input_file_path(__file__, filename)
18+
# Read the input files
19+
data: str = read_input_file(input_file_path)[0]
20+
except Exception as error:
21+
raise RuntimeError(f"Error: {error}")
22+
23+
# Solution Part 1
24+
num_positions = data.count('(') - data.count(')')
25+
26+
# Solution Part 2
27+
floor = 0
28+
elevator_map = {
29+
"(": 1,
30+
")": -1
31+
}
32+
num_position = 0
33+
for position, symbol in enumerate(data, start=1):
34+
if symbol in elevator_map:
35+
floor += elevator_map[symbol]
36+
if floor < 0:
37+
num_position = position
38+
break
39+
#
40+
return num_positions, num_position
41+
42+
43+
44+
45+
if __name__ == "__main__":
46+
# Import function to print results
47+
import time
48+
from utils.aoc_utils import print_day_results
49+
50+
# Calculate results for demo and real input files
51+
demo_1, demo_2 = solve_01_2015("input_demo.txt")
52+
start_time: float = time.time()
53+
solution_1, solution_2 = solve_01_2015("input.txt")
54+
end_time: float = time.time()
55+
56+
# Calculate execution time in milliseconds
57+
execution_time: int = int((end_time - start_time) * 1000)
58+
59+
# Print results in a formatted table (using rich)
60+
print_day_results(
61+
"2015", "01",
62+
str(demo_1), str(demo_2),
63+
str(solution_1), str(solution_2),
64+
execution_time
65+
)

advent_of_code/year_2015/day_01_not_quite_lisp/solution_one_01_2015.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

advent_of_code/year_2015/day_01_not_quite_lisp/solution_two_01_2015.py

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import os
22
from dotenv import load_dotenv
3-
from .solution_one_01_2015 import find_floor
4-
from .solution_two_01_2015 import find_index_position_enter_basement
3+
from .solution_day_01_2015 import solve_01_2015
54

65
load_dotenv()
76
environment = os.getenv("ENVIRONMENT")
@@ -14,14 +13,10 @@
1413

1514

1615
def test_day_01_2015():
17-
result_demo = find_floor(file_path_demo)
18-
assert result_demo == -3
19-
result_demo = find_index_position_enter_basement(file_path_demo)
20-
assert result_demo == 43
16+
results_demo = solve_01_2015(file_path_demo)
17+
assert results_demo == (-3, 43)
2118
if environment == "development":
22-
expected_result_one = int(os.getenv("SOLUTION_01_DAY_01_2015"))
23-
result_one = find_floor(file_path)
24-
assert expected_result_one == result_one
25-
expected_result_two = int(os.getenv("SOLUTION_02_DAY_01_2015"))
26-
result_two = find_index_position_enter_basement(file_path)
27-
assert expected_result_two == result_two
19+
expected_results = (int(os.getenv("SOLUTION_01_DAY_01_2015")),
20+
int(os.getenv("SOLUTION_02_DAY_01_2015")))
21+
results = solve_01_2015(file_path)
22+
assert expected_results == results

advent_of_code/year_2024/day_01_historian_hysteria/solution_day_01_2024.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def solve_day_01_2024(filename: str) -> tuple[int, int]:
4242
if __name__ == "__main__":
4343
# Import function to print results
4444
import time
45-
from utils.file_utils import print_day_results
45+
from utils.aoc_utils import print_day_results
4646

4747
# Calculate results for demo and real input files
4848
demo_1, demo_2 = solve_day_01_2024("input_demo.txt")

0 commit comments

Comments
 (0)