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.

66
15/3/main.py Normal file
View File

@@ -0,0 +1,66 @@
'''AoC day 2'''
def get_new_pos(curr_pos, instruction):
if instruction == '<':
new_pos = (curr_pos[0] - 1, curr_pos[1])
elif instruction == '>':
new_pos = (curr_pos[0] + 1, curr_pos[1])
elif instruction == '^':
new_pos = (curr_pos[0], curr_pos[1] + 1)
elif instruction == 'v':
new_pos = (curr_pos[0], curr_pos[1] - 1)
else:
new_pos = (0, 0)
return new_pos
def process_instructions(instruction_set: str) -> int:
'''Run through a set of instructions to return the number of unique houses visited
Keyword args:
instruction_set (str) - Directional arrow instruction string giving moves to new locations
Returns:
int - Number of unique houses visited
'''
visited_house_coordinates = {(0,0)}
curr_pos = (0, 0)
for instruction in instruction_set:
curr_pos = get_new_pos(curr_pos, instruction)
visited_house_coordinates.add(curr_pos)
return len(visited_house_coordinates)
def process_robo_instructions(instruction_set: str) -> int:
visited_house_coordinates = {(0,0)}
santa_pos = (0,0)
robot_pos = (0,0)
for index, instruction in enumerate(instruction_set):
if index % 2 == 0:
santa_pos = get_new_pos(santa_pos, instruction)
visited_house_coordinates.add(santa_pos)
else:
robot_pos = get_new_pos(robot_pos, instruction)
visited_house_coordinates.add(robot_pos)
return len(visited_house_coordinates)
def main():
'''Entrypoint'''
with open('input.txt', encoding='utf-8') as fh:
instruction_set = fh.readline()
unique_houses = process_instructions(instruction_set)
print(f'Part1: {unique_houses}')
robo_houses = process_robo_instructions(instruction_set)
print(f'Part2: {robo_houses}')
if __name__ == "__main__":
main()

20
15/3/test_day3.py Normal file
View File

@@ -0,0 +1,20 @@
import pytest
from main import process_instructions, process_robo_instructions
@pytest.mark.parametrize('given, expected',
[
('>', 2),
('^>v<', 4),
('^v^v^v^v^v', 2)
])
def test_instructions(given, expected):
assert process_instructions(given) == expected
@pytest.mark.parametrize('given, expected',
[
('^v', 3)
])
def test_part2_instructions(given, expected):
assert process_robo_instructions(given) == expected