You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1005 B
45 lines
1005 B
import sys
|
|
import os
|
|
import re
|
|
|
|
file = open('input.txt', 'r')
|
|
|
|
vowles = re.compile(r"([aeiou])")
|
|
doubles = re.compile(r"(.)\1")
|
|
naughty_combos = re.compile(r"(ab)|(cd)|(pq)|(xy)")
|
|
|
|
nice_words = 0
|
|
for line in file:
|
|
vowel_count = len(re.findall(vowles, line))
|
|
if vowel_count < 3:
|
|
continue
|
|
double_match = re.search(doubles, line)
|
|
if not double_match:
|
|
continue
|
|
naughty_match = re.search(naughty_combos, line)
|
|
if naughty_match:
|
|
continue
|
|
|
|
nice_words += 1
|
|
|
|
file.close()
|
|
print("Santas list has " + str(nice_words) + " nice words on it")
|
|
|
|
|
|
file = open('input.txt', 'r')
|
|
|
|
rule_1 = re.compile(r"(\w\w).*\1")
|
|
rule_2 = re.compile(r"(\w)\w\1")
|
|
|
|
new_nice_words = 0
|
|
for line in file:
|
|
rule_1_match = re.search(rule_1, line)
|
|
if not rule_1_match:
|
|
continue
|
|
rule_2_match = re.search(rule_2, line)
|
|
if not rule_2_match:
|
|
continue
|
|
|
|
new_nice_words += 1
|
|
|
|
print("Santas list has " + str(new_nice_words) + " new nice words on it")
|