Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. from re import findall
  2.  
  3. def nice(s):
  4. if 'ab' in s: return False
  5. if 'cd' in s: return False
  6. if 'pq' in s: return False
  7. if 'xy' in s: return False
  8.  
  9. found = False
  10. for i in range(0, len(s) - 2 + 1):
  11. if s[i] == s[i + 1]:
  12. found = True
  13. break
  14.  
  15. if not found: return False
  16.  
  17. return len(findall('[aeiou]', s)) >= 3
  18.  
  19. def nnice(s):
  20. found = False
  21. for i in range(0, len(s) - 3 + 1):
  22. if s[i] == s[i + 2]:
  23. found = True
  24. break
  25.  
  26. if not found: return False
  27.  
  28. found = False
  29. for i in range(0, len(s) - 2 + 1):
  30. for j in range(i + 2, len(s) - 1):
  31. if (s[i], s[i + 1]) == (s[j], s[j + 1]):
  32. found = True
  33. break
  34.  
  35. if not found: return False
  36.  
  37. return True
  38.  
  39. if __name__ == '__main__':
  40. assert nice('ugknbfddgicrmopn')
  41. assert nice('aaa')
  42. assert not nice('jchzalrnumimnmhp')
  43. assert not nice('haegwjzuvuyypxyu')
  44. assert not nice('dvszwmarrgswjxmb')
  45.  
  46. assert nnice('qjhvhtzxzqqjkmpb')
  47. assert nnice('xxyxx')
  48. assert not nnice('uurcxstgmygtbstg')
  49. assert not nnice('ieodomkazucvgmuy')
  50.  
  51. with open('./input') as f:
  52. words = f.read().strip().split('\n')
  53.  
  54. r = len(list(filter(nice, words)))
  55. print(r)
  56.  
  57. r = len(list(filter(nnice, words)))
  58. print(r)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement