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.

81
15/5/main.py Normal file
View File

@@ -0,0 +1,81 @@
def check_contains_no_bad_chars(test: str) -> bool:
bad_chars = ['ab', 'cd', 'pq', 'xy']
if any(el in test for el in bad_chars):
return False
return True
def check_doubled_char(input: str) -> bool:
for index, letter in enumerate(input):
if index - 1 > 0 and input[index - 1] == letter:
return True
if index + 1 < len(input) and input[index + 1] == letter:
return True
return False
def check_vowel_count(input: str) -> bool:
'''Give a count of vowels in a string
Keyword args:
input (str) - String to search to vowels
Return:
int - The number of found vowels
'''
sum = 0
for letter in input:
if letter in 'aeiou':
sum += 1
if sum > 2:
return True
return False
def check_if_nice(test: str) -> bool:
if check_contains_no_bad_chars(test) and check_doubled_char(test) and check_vowel_count(test):
return True
return False
def check_nonoverlapping_repeats(test: str) -> bool:
splitup = [test[i:i+2] for i in range(0, len(test), 2)]
for el in splitup:
check = splitup.pop()
if check in splitup:
return True
return False
def check_repeat_everyother(test: str) -> bool:
for index, letter in enumerate(test):
if index + 2 < len(test) and test[index+2] == letter:
return True
return False
def check_if_nice_part2(test: str) -> bool:
return check_nonoverlapping_repeats(test) and check_repeat_everyother(test)
def main():
with open('input.txt', encoding='utf-8') as fh:
total = 0
for line in fh:
# print(line.strip())
if check_if_nice(line.strip()):
total += 1
print(f'Part1: {total}')
if __name__ == "__main__":
main()

77
15/5/test_main.py Normal file
View File

@@ -0,0 +1,77 @@
import pytest
from main import check_contains_no_bad_chars, check_doubled_char, check_vowel_count, check_if_nice, check_nonoverlapping_repeats, check_repeat_everyother, check_if_nice_part2
@pytest.mark.parametrize('given, expected',
[
('aei', True),
('xazegov', True),
('aeiouaeiouaeiou', True),
('mnqpcbt', False)
])
def test_vowel_counting(given, expected):
assert check_vowel_count(given) == expected
@pytest.mark.parametrize('given, expected',
[
('aabbccdd', True),
('whythisword', False),
('hegwjzuvuyypxyu', True)
])
def test_double_counting(given, expected):
assert check_doubled_char(given) == expected
@pytest.mark.parametrize('given, expected',
[
('aabbccdd', False),
('whythisword', True)
])
def test_bad_chars(given, expected):
assert check_contains_no_bad_chars(given) == expected
@pytest.mark.parametrize('given, expected',
[
('ugknbfddgicrmopn', True),
('aaa', True),
('jchzalrnumimnmhp', False),
('haegwjzuvuyypxyu', False),
('dvszwmarrgswjxmb', False)
])
def test_examples(given, expected):
assert check_if_nice(given) == expected
@pytest.mark.parametrize('given, expected',
[
('xyxy', True),
('xxyxx', True),
('aaa', False)
])
def test_nonopverlapping(given, expected):
assert check_nonoverlapping_repeats(given) == expected
@pytest.mark.parametrize('given, expected',
[
('xyx', True),
('xxyxx', True),
('abcdefeghi', True),
('aaa', True),
('blargh', False)
])
def test_repeat_everyother(given, expected):
assert check_repeat_everyother(given) == expected
@pytest.mark.parametrize('given, expected',
[
('qjhvhtzxzqqjkmpb', True),
('xxyxx', True),
('uurcxstgmygtbstg', False),
('ieodomkazucvgmuy', False)
])
def test_part2_examples(given, expected):
assert check_if_nice_part2(given) == expected