37 lines
732 B
Python
37 lines
732 B
Python
import sys
|
|
|
|
VOWELS = "aeiou"
|
|
FORBIDDEN = {"ab", "cd", "pq", "xy"}
|
|
|
|
|
|
def is_nice_1(s: str) -> bool:
|
|
if sum(c in VOWELS for c in s) < 3:
|
|
return False
|
|
|
|
if not any(a == b for a, b in zip(s[:-1:], s[1::])):
|
|
return False
|
|
|
|
if any(s.find(f) >= 0 for f in FORBIDDEN):
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
def is_nice_2(s: str) -> bool:
|
|
if not any(s.find(s[i : i + 2], i + 2) >= 0 for i in range(len(s))):
|
|
return False
|
|
|
|
if not any(a == b for a, b in zip(s[:-1:], s[2::])):
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
lines = sys.stdin.read().splitlines()
|
|
|
|
answer_1 = sum(map(is_nice_1, lines))
|
|
print(f"answer 1 is {answer_1}")
|
|
|
|
answer_2 = sum(map(is_nice_2, lines))
|
|
print(f"answer 2 is {answer_2}")
|