-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
part1.py
47 lines (35 loc) · 1.08 KB
/
part1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from collections import Counter
class StringChecker:
def __init__(self, string):
self.string = string
def check_excluded(self):
return not any(exc in self.string for exc in excluded)
def check_vowels(self):
count = Counter(self.string)
vowel_count = 0
for vowel in vowels:
vowel_count += count[vowel]
if vowel_count >= 3:
return True
def check_twice(self):
twice_count = 0
for i, char in enumerate(self.string):
try:
if char == self.string[i + 1]:
twice_count += 1
except IndexError:
pass
if twice_count >= 1:
return True
with open('input.txt', 'r') as f:
strings = f.read().splitlines()
vowels = ['a', 'e', 'i', 'o', 'u']
excluded = ['ab', 'cd', 'pq', 'xy']
nice_count = 0
for string in strings:
checker = StringChecker(string)
if checker.check_excluded():
if checker.check_vowels():
if checker.check_twice():
nice_count += 1
print(nice_count)