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()