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.

48
25/2/main.py Normal file
View File

@@ -0,0 +1,48 @@
'''AoC Day 2'''
import re
def part1(range_list: list) -> int:
'''Part 1'''
total = 0
for id_range in range_list:
for x in range(int(id_range[0]), int(id_range[1]) + 1):
if not check_valid_id(str(x)):
total += x
return total
def part2(range_list: list) -> int:
'''Part 2'''
total = 0
for id_range in range_list:
for x in range(int(id_range[0]), int(id_range[1]) + 1):
if not check_extended_id(str(x)):
total += x
return total
def check_valid_id(id: str) -> bool:
'''Checks a given ID for validity using the silly rules'''
return re.fullmatch(r'(.*?)\1', id) is None
def check_extended_id(id: str) -> bool:
'''Checks for extended rule checking, at least two repeats'''
return re.fullmatch(r'(.*?)\1+', id) is None
def main():
'''Entrypoint'''
with open('input.txt', encoding='utf-8') as fh:
range_list = [(y[0].strip(), y[1].strip()) for y in (x.split('-') for x in fh.readline().split(','))]
total = part1(range_list)
print(f'Part1: {total}')
total2 = part2(range_list)
print(f'Part2: {total2}')
if __name__ == "__main__":
main()

87
25/2/test_main.py Normal file
View File

@@ -0,0 +1,87 @@
import pytest
from main import check_valid_id, check_extended_id, part1, part2
@pytest.mark.parametrize('given, expected',
[
('1', True),
('11', False),
('12', True),
('22', False),
('1010', False),
('1012', True),
('1188511885', False),
('222222', False),
('446446', False),
('565656', True),
('446447', True),
('38593859', False),
('385385385', True)
])
def test_check_valid_id(given, expected):
assert check_valid_id(given) == expected
@pytest.mark.parametrize('given, expected',
[
('1', True),
('12', True),
('1012', True),
('446447', True),
('11', False),
('22', False),
('99', False),
('111', False),
('999', False),
('1010', False),
('1188511885', False),
('222222', False),
('446446', False),
('565656', False),
('38593859', False),
('385385385', False),
('824824824', False),
('2121212121', False)
])
def test_extended_valid_id(given, expected):
assert check_extended_id(given) == expected
@pytest.mark.parametrize('given, expected',
[
(
[
('11', '22'),
('95', '115'),
('998', '1012'),
('1188511880', '1188511890'),
('222220', '222224'),
('1698522', '1698528'),
('446443', '446449'),
('38593856', '38593862')
],
1227775554
)
])
def test_part1_examples(given, expected):
assert part1(given) == expected
@pytest.mark.parametrize('given, expected',
[
(
[
('11', '22'),
('95', '115'),
('998', '1012'),
('1188511880', '1188511890'),
('222220', '222224'),
('1698522', '1698528'),
('446443', '446449'),
('38593856', '38593862'),
('565653', '565659'),
('824824821', '824824827'),
('2121212118', '2121212124')
],
4174379265
)
])
def test_part2_examples(given, expected):
assert part2(given) == expected