Add code for 2015 advent that I did historically.
This commit is contained in:
parent
13968ed94e
commit
9e9e556c73
25 changed files with 598 additions and 0 deletions
33
day_5/part_1.py
Normal file
33
day_5/part_1.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import re
|
||||
|
||||
|
||||
forbidden_sequences = [ "ab", "cd", "pq", "xy" ]
|
||||
double_letter_pattern = r"(?P<char>[A-Za-z])(?P=char)"
|
||||
|
||||
|
||||
def has_three_vowels(string):
|
||||
vowel_count = 0
|
||||
for char in string:
|
||||
if char in "aeiou":
|
||||
vowel_count += 1
|
||||
return vowel_count >= 3
|
||||
|
||||
|
||||
def has_double_letter(string):
|
||||
return re.search(double_letter_pattern, string) != None
|
||||
|
||||
|
||||
def no_forbidden_sequences(string):
|
||||
for sequence in forbidden_sequences:
|
||||
if sequence in string:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
total_nice_lines = 0
|
||||
data = open("input", "r")
|
||||
for line in data:
|
||||
if has_three_vowels(line) and has_double_letter(line) and no_forbidden_sequences(line):
|
||||
total_nice_lines += 1
|
||||
data.close()
|
||||
print(f"Total Nice Lines: {total_nice_lines}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue