Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from re import findall
- def nice(s):
- if 'ab' in s: return False
- if 'cd' in s: return False
- if 'pq' in s: return False
- if 'xy' in s: return False
- found = False
- for i in range(0, len(s) - 2 + 1):
- if s[i] == s[i + 1]:
- found = True
- break
- if not found: return False
- return len(findall('[aeiou]', s)) >= 3
- def nnice(s):
- found = False
- for i in range(0, len(s) - 3 + 1):
- if s[i] == s[i + 2]:
- found = True
- break
- if not found: return False
- found = False
- for i in range(0, len(s) - 2 + 1):
- for j in range(i + 2, len(s) - 1):
- if (s[i], s[i + 1]) == (s[j], s[j + 1]):
- found = True
- break
- if not found: return False
- return True
- if __name__ == '__main__':
- assert nice('ugknbfddgicrmopn')
- assert nice('aaa')
- assert not nice('jchzalrnumimnmhp')
- assert not nice('haegwjzuvuyypxyu')
- assert not nice('dvszwmarrgswjxmb')
- assert nnice('qjhvhtzxzqqjkmpb')
- assert nnice('xxyxx')
- assert not nnice('uurcxstgmygtbstg')
- assert not nnice('ieodomkazucvgmuy')
- with open('./input') as f:
- words = f.read().strip().split('\n')
- r = len(list(filter(nice, words)))
- print(r)
- r = len(list(filter(nnice, words)))
- print(r)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement