## Day 5, Year 2015: Doesn't He Have Intern-Elves For This?

def nice(s):
prev_ch = None
vowels = 0
doubles = 0
disallowed_strings = 0
for ch in s:
if ch in ('a', 'e', 'i', 'o', 'u'):
vowels += 1

if ch == prev_ch:
doubles += 1

if prev_ch and prev_ch + ch in ('ab', 'cd', 'pq', 'xy'):
disallowed_strings += 1

prev_ch = ch

return vowels >= 3 and \
doubles >= 1 and \
disallowed_strings == 0
assert nice('ugknbfddgicrmopn') == True
assert nice('aaa') == True
assert nice('jchzalrnumimnmhp') == False
assert nice('haegwjzuvuyypxyu') == False
assert nice('dvszwmarrgswjxmb') == False
import import_ipynb
import helper
s = helper.read_file('2015_5.txt')
sum(map(nice, s.splitlines()))
255
def nice2(s):
doubles = 0
repeating = 0

for i in range(len(s)):
if i > len(s)-3:
break

if s[i] == s[i+2]:
repeating += 1

for j in range(i+2, len(s)-1):
if s[i] == s[j] and s[i+1] == s[j+1]:
doubles += 1

return doubles >= 1 and repeating >= 1
assert nice2('qjhvhtzxzqqjkmpb') == True
assert nice2('xxyxx') == True
assert nice2('uurcxstgmygtbstg') == False
assert nice2('ieodomkazucvgmuy') == False
sum(map(nice2, s.splitlines()))
55