All checks were successful
continuous-integration/drone/push Build is passing
Co-authored-by: Mikael CAPELLE <mikael.capelle@thalesaleniaspace.com> Co-authored-by: Mikaël Capelle <capelle.mikael@gmail.com> Reviewed-on: #3
37 lines
796 B
Python
37 lines
796 B
Python
from typing import Any, Iterator
|
|
|
|
from ..base import BaseSolver
|
|
|
|
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
|
|
|
|
|
|
class Solver(BaseSolver):
|
|
def solve(self, input: str) -> Iterator[Any]:
|
|
lines = input.splitlines()
|
|
yield sum(map(is_nice_1, lines))
|
|
yield sum(map(is_nice_2, lines))
|