feat: Redo of the AoC repo starting over with 2015 and keeping up with

2025 (completed day 2 so far)
This commit is contained in:
2025-12-02 07:55:08 -06:00
commit c936d7d573
29 changed files with 668 additions and 0 deletions

Binary file not shown.

59
15/1/main.py Normal file
View File

@@ -0,0 +1,59 @@
'''Day 1 of 2015 AOC'''
def process_input_string(input_string: str) -> int:
'''Take in an input string and give back the floor number based on the instructions.
Keyword Args:
input_string (str) - String of encoded instructions
Return:
int - Floor number
'''
curr_floor = 0
for char in input_string:
if char == '(':
curr_floor += 1
elif char == ')':
curr_floor -= 1
return curr_floor
def find_the_basement(input_string: str) -> int:
'''Take in an input string of instructions and give back the position of the instruction entering the basement, or hitting floor "-1".
Keyword Args:
input_string (str) - String of encoded instructions
Return:
int - Position of instruction in the string
'''
curr_floor = 0
for index, char in enumerate(input_string):
if char == '(':
curr_floor += 1
elif char == ')':
curr_floor -= 1
if curr_floor == -1:
# Add one to give the 1s based position instead of the 0s based index
return index + 1
def main():
'''Entrypoint'''
with open('input.txt', encoding='utf-8') as fh:
input_string = fh.readline()
output = process_input_string(input_string)
print(f'Part 1: {output}')
output = find_the_basement(input_string)
print(f'Part 2: {output}')
if __name__ == "__main__":
main()

28
15/1/test_day1.py Normal file
View File

@@ -0,0 +1,28 @@
import pytest
from main import find_the_basement, process_input_string
@pytest.mark.parametrize('test_input, expected',
[
('(())', 0),
('()()', 0),
('(((', 3),
('(()(()(', 3),
('))(((((', 3),
('())', -1),
('))(', -1),
(')))', -3),
(')())())', -3)
])
def test_instruction_examples(test_input, expected):
assert process_input_string(test_input) == expected
@pytest.mark.parametrize('test_input, expected',
[
(')', 1),
('()())', 5)
])
def test_basement_instructions(test_input, expected):
assert find_the_basement(test_input) == expected