2015: d05: ex1: add solution
This commit is contained in:
parent
a1c3ca2381
commit
5134d471d9
1 changed files with 28 additions and 0 deletions
28
2015/d05/ex1/ex1.py
Executable file
28
2015/d05/ex1/ex1.py
Executable file
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import collections
|
||||
import sys
|
||||
|
||||
|
||||
def solve(input: str) -> int:
|
||||
def is_nice(input: str) -> bool:
|
||||
counts = collections.Counter(input)
|
||||
if sum(counts[c] for c in "aeiou") < 3:
|
||||
return False
|
||||
if not any((c + c) in input for c in (chr(ord("a") + i) for i in range(26))):
|
||||
return False
|
||||
for bad in ("ab", "cd", "pq", "xy"):
|
||||
if bad in input:
|
||||
return False
|
||||
return True
|
||||
|
||||
return sum(map(is_nice, input.splitlines()))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = sys.stdin.read()
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue